@insforge/sdk 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -369,7 +369,6 @@ declare class Database {
369
369
  /**
370
370
  * Storage module for InsForge SDK
371
371
  * Handles file uploads, downloads, and bucket management
372
- * Supports both presigned URLs (S3) and direct uploads (local)
373
372
  */
374
373
 
375
374
  interface StorageResponse<T> {
@@ -384,26 +383,18 @@ declare class StorageBucket {
384
383
  private http;
385
384
  constructor(bucketName: string, http: HttpClient);
386
385
  /**
387
- * Upload a file with a specific key using the appropriate strategy
386
+ * Upload a file with a specific key
388
387
  * @param path - The object key/path
389
388
  * @param file - File or Blob to upload
390
389
  */
391
390
  upload(path: string, file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
392
- /**
393
- * Upload using presigned URL (for S3)
394
- */
395
- private uploadPresigned;
396
- /**
397
- * Upload directly to backend (for local storage)
398
- */
399
- private uploadDirect;
400
391
  /**
401
392
  * Upload a file with auto-generated key
402
393
  * @param file - File or Blob to upload
403
394
  */
404
395
  uploadAuto(file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
405
396
  /**
406
- * Download a file using the appropriate strategy
397
+ * Download a file
407
398
  * @param path - The object key/path
408
399
  * Returns the file as a Blob
409
400
  */
@@ -412,15 +403,7 @@ declare class StorageBucket {
412
403
  error: InsForgeError | null;
413
404
  }>;
414
405
  /**
415
- * Download using presigned URL (for S3)
416
- */
417
- private downloadPresigned;
418
- /**
419
- * Download directly from backend (for local storage)
420
- */
421
- private downloadDirect;
422
- /**
423
- * Get public URL for a file (direct URL, may not work for private S3)
406
+ * Get public URL for a file
424
407
  * @param path - The object key/path
425
408
  */
426
409
  getPublicUrl(path: string): string;
package/dist/index.d.ts CHANGED
@@ -369,7 +369,6 @@ declare class Database {
369
369
  /**
370
370
  * Storage module for InsForge SDK
371
371
  * Handles file uploads, downloads, and bucket management
372
- * Supports both presigned URLs (S3) and direct uploads (local)
373
372
  */
374
373
 
375
374
  interface StorageResponse<T> {
@@ -384,26 +383,18 @@ declare class StorageBucket {
384
383
  private http;
385
384
  constructor(bucketName: string, http: HttpClient);
386
385
  /**
387
- * Upload a file with a specific key using the appropriate strategy
386
+ * Upload a file with a specific key
388
387
  * @param path - The object key/path
389
388
  * @param file - File or Blob to upload
390
389
  */
391
390
  upload(path: string, file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
392
- /**
393
- * Upload using presigned URL (for S3)
394
- */
395
- private uploadPresigned;
396
- /**
397
- * Upload directly to backend (for local storage)
398
- */
399
- private uploadDirect;
400
391
  /**
401
392
  * Upload a file with auto-generated key
402
393
  * @param file - File or Blob to upload
403
394
  */
404
395
  uploadAuto(file: File | Blob): Promise<StorageResponse<StorageFileSchema>>;
405
396
  /**
406
- * Download a file using the appropriate strategy
397
+ * Download a file
407
398
  * @param path - The object key/path
408
399
  * Returns the file as a Blob
409
400
  */
@@ -412,15 +403,7 @@ declare class StorageBucket {
412
403
  error: InsForgeError | null;
413
404
  }>;
414
405
  /**
415
- * Download using presigned URL (for S3)
416
- */
417
- private downloadPresigned;
418
- /**
419
- * Download directly from backend (for local storage)
420
- */
421
- private downloadDirect;
422
- /**
423
- * Get public URL for a file (direct URL, may not work for private S3)
406
+ * Get public URL for a file
424
407
  * @param path - The object key/path
425
408
  */
426
409
  getPublicUrl(path: string): string;
package/dist/index.js CHANGED
@@ -761,101 +761,11 @@ var StorageBucket = class {
761
761
  this.http = http;
762
762
  }
763
763
  /**
764
- * Upload a file with a specific key using the appropriate strategy
764
+ * Upload a file with a specific key
765
765
  * @param path - The object key/path
766
766
  * @param file - File or Blob to upload
767
767
  */
768
768
  async upload(path, file) {
769
- try {
770
- const strategyRequest = {
771
- filename: path,
772
- contentType: file.type || "application/octet-stream",
773
- size: file.size
774
- };
775
- const strategy = await this.http.post(
776
- `/api/storage/buckets/${this.bucketName}/upload-strategy`,
777
- strategyRequest
778
- );
779
- if (!strategy) {
780
- throw new InsForgeError("Failed to get upload strategy", 500, "STORAGE_ERROR");
781
- }
782
- if (strategy.method === "presigned") {
783
- return await this.uploadPresigned(strategy, file);
784
- } else {
785
- return await this.uploadDirect(path, file);
786
- }
787
- } catch (error) {
788
- return {
789
- data: null,
790
- error: error instanceof InsForgeError ? error : new InsForgeError(
791
- "Upload failed",
792
- 500,
793
- "STORAGE_ERROR"
794
- )
795
- };
796
- }
797
- }
798
- /**
799
- * Upload using presigned URL (for S3)
800
- */
801
- async uploadPresigned(strategy, file) {
802
- try {
803
- const formData = new FormData();
804
- if (strategy.fields) {
805
- Object.entries(strategy.fields).forEach(([key, value]) => {
806
- formData.append(key, value);
807
- });
808
- }
809
- formData.append("file", file);
810
- const uploadResponse = await fetch(strategy.uploadUrl, {
811
- method: "POST",
812
- body: formData
813
- });
814
- if (!uploadResponse.ok) {
815
- const text = await uploadResponse.text();
816
- throw new InsForgeError(
817
- `Presigned upload failed: ${text}`,
818
- uploadResponse.status,
819
- "STORAGE_ERROR"
820
- );
821
- }
822
- if (strategy.confirmRequired && strategy.confirmUrl) {
823
- const confirmRequest = {
824
- size: file.size,
825
- contentType: file.type || "application/octet-stream"
826
- };
827
- const confirmResponse = await this.http.post(
828
- strategy.confirmUrl,
829
- confirmRequest
830
- );
831
- return { data: confirmResponse, error: null };
832
- }
833
- return {
834
- data: {
835
- bucket: this.bucketName,
836
- key: strategy.key,
837
- size: file.size,
838
- mimeType: file.type,
839
- uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
840
- url: this.getPublicUrl(strategy.key)
841
- },
842
- error: null
843
- };
844
- } catch (error) {
845
- return {
846
- data: null,
847
- error: error instanceof InsForgeError ? error : new InsForgeError(
848
- "Presigned upload failed",
849
- 500,
850
- "STORAGE_ERROR"
851
- )
852
- };
853
- }
854
- }
855
- /**
856
- * Upload directly to backend (for local storage)
857
- */
858
- async uploadDirect(path, file) {
859
769
  try {
860
770
  const formData = new FormData();
861
771
  formData.append("file", file);
@@ -874,7 +784,7 @@ var StorageBucket = class {
874
784
  return {
875
785
  data: null,
876
786
  error: error instanceof InsForgeError ? error : new InsForgeError(
877
- "Direct upload failed",
787
+ "Upload failed",
878
788
  500,
879
789
  "STORAGE_ERROR"
880
790
  )
@@ -912,78 +822,11 @@ var StorageBucket = class {
912
822
  }
913
823
  }
914
824
  /**
915
- * Download a file using the appropriate strategy
825
+ * Download a file
916
826
  * @param path - The object key/path
917
827
  * Returns the file as a Blob
918
828
  */
919
829
  async download(path) {
920
- try {
921
- const strategyRequest = {
922
- expiresIn: 3600
923
- // 1 hour default
924
- };
925
- const strategy = await this.http.post(
926
- `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,
927
- strategyRequest
928
- );
929
- if (!strategy) {
930
- return await this.downloadDirect(path);
931
- }
932
- if (strategy.method === "presigned") {
933
- return await this.downloadPresigned(strategy);
934
- } else {
935
- return await this.downloadDirect(path);
936
- }
937
- } catch (error) {
938
- return {
939
- data: null,
940
- error: error instanceof InsForgeError ? error : new InsForgeError(
941
- "Download failed",
942
- 500,
943
- "STORAGE_ERROR"
944
- )
945
- };
946
- }
947
- }
948
- /**
949
- * Download using presigned URL (for S3)
950
- */
951
- async downloadPresigned(strategy) {
952
- try {
953
- const headers = {};
954
- if (strategy.headers) {
955
- Object.entries(strategy.headers).forEach(([key, value]) => {
956
- headers[key] = value;
957
- });
958
- }
959
- const response = await fetch(strategy.url, {
960
- method: "GET",
961
- headers
962
- });
963
- if (!response.ok) {
964
- throw new InsForgeError(
965
- `Download failed: ${response.statusText}`,
966
- response.status,
967
- "STORAGE_ERROR"
968
- );
969
- }
970
- const blob = await response.blob();
971
- return { data: blob, error: null };
972
- } catch (error) {
973
- return {
974
- data: null,
975
- error: error instanceof InsForgeError ? error : new InsForgeError(
976
- "Presigned download failed",
977
- 500,
978
- "STORAGE_ERROR"
979
- )
980
- };
981
- }
982
- }
983
- /**
984
- * Download directly from backend (for local storage)
985
- */
986
- async downloadDirect(path) {
987
830
  try {
988
831
  const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;
989
832
  const response = await this.http.fetch(url, {
@@ -1008,17 +851,15 @@ var StorageBucket = class {
1008
851
  return {
1009
852
  data: null,
1010
853
  error: error instanceof InsForgeError ? error : new InsForgeError(
1011
- "Direct download failed",
854
+ "Download failed",
1012
855
  500,
1013
856
  "STORAGE_ERROR"
1014
857
  )
1015
858
  };
1016
859
  }
1017
860
  }
1018
- // Removed getSignedUrl - this is handled internally by download()
1019
- // The SDK abstracts away presigned URL complexity
1020
861
  /**
1021
- * Get public URL for a file (direct URL, may not work for private S3)
862
+ * Get public URL for a file
1022
863
  * @param path - The object key/path
1023
864
  */
1024
865
  getPublicUrl(path) {
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.ts","../src/modules/auth.ts","../src/modules/storage.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 and types\nexport { Database, QueryBuilder } from './modules/database';\nexport type { DatabaseResponse } from './modules/database';\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\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 URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n url?: string;\n\n /**\n * API key (optional)\n * Can be used for server-side operations or specific use cases\n */\n apiKey?: 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\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.url || '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.defaultHeaders = {\n ...config.headers,\n };\n \n // Add API key if provided\n if (config.apiKey) {\n this.defaultHeaders['Authorization'] = `Bearer ${config.apiKey}`;\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 url.searchParams.append(key, value);\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 // 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 throw InsForgeError.fromApiError(data as ApiError);\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 if (token) {\n this.defaultHeaders['Authorization'] = `Bearer ${token}`;\n } else {\n delete this.defaultHeaders['Authorization'];\n }\n }\n\n getHeaders(): Record<string, string> {\n return { ...this.defaultHeaders };\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 for InsForge SDK\n * Supabase-style query builder for PostgREST operations\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\n\nexport interface DatabaseResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n count?: number;\n}\n\n/**\n * Query builder for database operations\n * Uses method chaining like Supabase\n */\nexport class QueryBuilder<T = any> {\n private method: 'GET' | 'POST' | 'PATCH' | 'DELETE' = 'GET';\n private headers: Record<string, string> = {};\n private queryParams: Record<string, string> = {};\n private body?: any;\n\n constructor(\n private table: string,\n private http: HttpClient\n ) {}\n\n /**\n * Perform a SELECT query\n * For mutations (insert/update/delete), this enables returning data\n * @param columns - Columns to select (default: '*')\n * @example\n * .select('*')\n * .select('id, title, content')\n * .select('*, users!inner(*)') // Join with users table\n * .select('*, profile:profiles(*)') // Join with alias\n * .insert({ title: 'New' }).select() // Returns inserted data\n */\n select(columns: string = '*'): this {\n // For mutations, add return=representation header\n if (this.method !== 'GET') {\n const existingPrefer = this.headers['Prefer'] || '';\n const preferParts = existingPrefer ? [existingPrefer] : [];\n if (!preferParts.some(p => p.includes('return='))) {\n preferParts.push('return=representation');\n }\n this.headers['Prefer'] = preferParts.join(',');\n }\n \n // Always set the select parameter for GET requests\n // This enables PostgREST joins and nested queries\n if (this.method === 'GET' && columns) {\n this.queryParams.select = columns;\n } else if (columns !== '*') {\n // For mutations, only set if not default\n this.queryParams.select = columns;\n }\n return this;\n }\n\n /**\n * Perform an INSERT\n * @param values - Single object or array of objects\n * @param options - { upsert: true } for upsert behavior\n * @example\n * .insert({ title: 'Hello', content: 'World' }).select()\n * .insert([{ title: 'Post 1' }, { title: 'Post 2' }]).select()\n */\n insert(values: Partial<T> | Partial<T>[], options?: { upsert?: boolean }): this {\n this.method = 'POST';\n this.body = Array.isArray(values) ? values : [values];\n \n if (options?.upsert) {\n this.headers['Prefer'] = 'resolution=merge-duplicates';\n }\n \n return this;\n }\n\n /**\n * Perform an UPDATE\n * @param values - Object with fields to update\n * @example\n * .update({ title: 'Updated Title' }).select()\n */\n update(values: Partial<T>): this {\n this.method = 'PATCH';\n this.body = values;\n return this;\n }\n\n /**\n * Perform a DELETE\n * @example\n * .delete().select()\n */\n delete(): this {\n this.method = 'DELETE';\n return this;\n }\n\n /**\n * Perform an UPSERT\n * @param values - Single object or array of objects\n * @example\n * .upsert({ id: 1, title: 'Hello' })\n */\n upsert(values: Partial<T> | Partial<T>[]): this {\n return this.insert(values, { upsert: true });\n }\n\n // FILTERS\n\n /**\n * Filter by column equal to value\n * @example .eq('id', 123)\n */\n eq(column: string, value: any): this {\n this.queryParams[column] = `eq.${value}`;\n return this;\n }\n\n /**\n * Filter by column not equal to value\n * @example .neq('status', 'draft')\n */\n neq(column: string, value: any): this {\n this.queryParams[column] = `neq.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than value\n * @example .gt('age', 18)\n */\n gt(column: string, value: any): this {\n this.queryParams[column] = `gt.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than or equal to value\n * @example .gte('price', 100)\n */\n gte(column: string, value: any): this {\n this.queryParams[column] = `gte.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than value\n * @example .lt('stock', 10)\n */\n lt(column: string, value: any): this {\n this.queryParams[column] = `lt.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than or equal to value\n * @example .lte('discount', 50)\n */\n lte(column: string, value: any): this {\n this.queryParams[column] = `lte.${value}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-sensitive)\n * @example .like('email', '%@gmail.com')\n */\n like(column: string, pattern: string): this {\n this.queryParams[column] = `like.${pattern}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-insensitive)\n * @example .ilike('name', '%john%')\n */\n ilike(column: string, pattern: string): this {\n this.queryParams[column] = `ilike.${pattern}`;\n return this;\n }\n\n /**\n * Filter by checking if column is a value\n * @example .is('deleted_at', null)\n */\n is(column: string, value: null | boolean): this {\n if (value === null) {\n this.queryParams[column] = 'is.null';\n } else {\n this.queryParams[column] = `is.${value}`;\n }\n return this;\n }\n\n /**\n * Filter by checking if value is in array\n * @example .in('status', ['active', 'pending'])\n */\n in(column: string, values: any[]): this {\n this.queryParams[column] = `in.(${values.join(',')})`;\n return this;\n }\n\n // MODIFIERS\n\n /**\n * Order by column\n * @example \n * .order('created_at') // ascending\n * .order('created_at', { ascending: false }) // descending\n */\n order(column: string, options?: { ascending?: boolean }): this {\n const ascending = options?.ascending !== false;\n this.queryParams.order = ascending ? column : `${column}.desc`;\n return this;\n }\n\n /**\n * Limit the number of rows returned\n * @example .limit(10)\n */\n limit(count: number): this {\n this.queryParams.limit = count.toString();\n return this;\n }\n\n /**\n * Return results from an offset\n * @example .offset(20)\n */\n offset(count: number): this {\n this.queryParams.offset = count.toString();\n return this;\n }\n\n /**\n * Set a range of rows to return\n * @example .range(0, 9) // First 10 rows\n */\n range(from: number, to: number): this {\n this.headers['Range'] = `${from}-${to}`;\n return this;\n }\n\n /**\n * Return a single object instead of array\n * @example .single()\n */\n single(): this {\n this.headers['Accept'] = 'application/vnd.pgrst.object+json';\n return this;\n }\n\n /**\n * Get the total count (use with select)\n * @example .select('*', { count: 'exact' })\n */\n count(algorithm: 'exact' | 'planned' | 'estimated' = 'exact'): this {\n const prefer = this.headers['Prefer'] || '';\n this.headers['Prefer'] = prefer ? `${prefer},count=${algorithm}` : `count=${algorithm}`;\n return this;\n }\n\n /**\n * Execute the query and return results\n */\n async execute(): Promise<DatabaseResponse<T>> {\n try {\n const path = `/api/database/records/${this.table}`;\n let response: any;\n\n switch (this.method) {\n case 'GET':\n response = await this.http.get<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'POST':\n response = await this.http.post<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'PATCH':\n response = await this.http.patch<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'DELETE':\n response = await this.http.delete<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\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 'Database operation failed',\n 500,\n 'DATABASE_ERROR'\n )\n };\n }\n }\n\n /**\n * Make QueryBuilder thenable for async/await\n */\n then<TResult1 = DatabaseResponse<T>, TResult2 = never>(\n onfulfilled?: ((value: DatabaseResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): Promise<TResult1 | TResult2> {\n return this.execute().then(onfulfilled, onrejected);\n }\n}\n\n/**\n * Database client for InsForge SDK\n * Provides Supabase-style interface\n */\nexport class Database {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a query builder for a table\n * @param table - The table name\n * @example\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId)\n * .order('created_at', { ascending: false })\n * .limit(10);\n */\n from<T = any>(table: string): QueryBuilder<T> {\n return new QueryBuilder<T>(table, this.http);\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';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\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);\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: 'google' | 'github';\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: InsForgeError | 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 if (profileError && profileError.statusCode !== 406) { // 406 = 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: InsForgeError | 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.statusCode === 406) {\n return { data: null, error: null };\n }\n \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 async getCurrentSession(): Promise<{\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: InsForgeError | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.user?.id) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n\n // Update the profile using query builder\n return await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n * Supports both presigned URLs (S3) and direct uploads (local)\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema,\n UploadStrategyRequest,\n UploadStrategyResponse,\n DownloadStrategyRequest,\n DownloadStrategyResponse,\n ConfirmUploadRequest\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\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 using the appropriate strategy\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 // Step 1: Get upload strategy from backend\n const strategyRequest: UploadStrategyRequest = {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n };\n\n const strategy = await this.http.post<UploadStrategyResponse>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n strategyRequest\n );\n \n if (!strategy) {\n throw new InsForgeError('Failed to get upload strategy', 500, 'STORAGE_ERROR');\n }\n\n // Step 2: Upload based on strategy\n if (strategy.method === 'presigned') {\n return await this.uploadPresigned(strategy, file);\n } else {\n return await this.uploadDirect(path, file);\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 using presigned URL (for S3)\n */\n private async uploadPresigned(\n strategy: UploadStrategyResponse,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Step 1: Upload to presigned URL\n const formData = new FormData();\n \n // Add any fields from the strategy (S3 requires these)\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be added last for S3\n formData.append('file', file);\n\n // Upload directly to S3 (or presigned URL)\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n const text = await uploadResponse.text();\n throw new InsForgeError(\n `Presigned upload failed: ${text}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Step 2: Confirm upload with backend\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmRequest: ConfirmUploadRequest = {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n };\n\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n confirmRequest\n );\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, construct response\n return {\n data: {\n bucket: this.bucketName,\n key: strategy.key,\n size: file.size,\n mimeType: file.type,\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n },\n error: null\n };\n } catch (error) {\n return {\n data: null,\n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload directly to backend (for local storage)\n */\n private async uploadDirect(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const formData = new FormData();\n formData.append('file', file);\n\n // Use PUT for specific path\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 } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Direct upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // For auto-generated keys, always use POST directly to backend\n // The backend will handle the strategy internally\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 } 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 * Download a file using the appropriate strategy\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 // Step 1: Get download strategy from backend\n const strategyRequest: DownloadStrategyRequest = {\n expiresIn: 3600 // 1 hour default\n };\n\n const strategy = await this.http.post<DownloadStrategyResponse>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n strategyRequest\n );\n \n if (!strategy) {\n // Fallback to direct download\n return await this.downloadDirect(path);\n }\n\n // Step 2: Download based on strategy\n if (strategy.method === 'presigned') {\n return await this.downloadPresigned(strategy);\n } else {\n return await this.downloadDirect(path);\n }\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 * Download using presigned URL (for S3)\n */\n private async downloadPresigned(\n strategy: DownloadStrategyResponse\n ): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n const headers: HeadersInit = {};\n \n // Add any headers from the strategy\n if (strategy.headers) {\n Object.entries(strategy.headers).forEach(([key, value]) => {\n headers[key] = value;\n });\n }\n\n const response = await fetch(strategy.url, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\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 'Presigned download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Download directly from backend (for local storage)\n */\n private async downloadDirect(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n \n const response = await this.http.fetch(url, {\n method: 'GET',\n headers: this.http.getHeaders()\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 'Direct download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n // Removed getSignedUrl - this is handled internally by download()\n // The SDK abstracts away presigned URL complexity\n\n /**\n * Get public URL for a file (direct URL, may not work for private S3)\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}","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';\nimport { Storage } from './modules/storage';\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 */\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\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http);\n this.storage = new Storage(this.http);\n }\n\n\n /**\n * Set a custom API key for authentication\n * This is useful for server-to-server communication\n * \n * @param apiKey - The API key (should start with 'ik_')\n * \n * @example\n * ```typescript\n * client.setApiKey('ik_your_api_key_here');\n * ```\n */\n setApiKey(apiKey: string): void {\n // API keys can be used as Bearer tokens\n this.http.setAuthToken(apiKey);\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;;;ACmEO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,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WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,UAAU,QAAsB;AAE9B,SAAK,KAAK,aAAa,MAAM;AAAA,EAC/B;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;;;APpDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database.ts","../src/modules/auth.ts","../src/modules/storage.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 and types\nexport { Database, QueryBuilder } from './modules/database';\nexport type { DatabaseResponse } from './modules/database';\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\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 URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n url?: string;\n\n /**\n * API key (optional)\n * Can be used for server-side operations or specific use cases\n */\n apiKey?: 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\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.url || '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.defaultHeaders = {\n ...config.headers,\n };\n \n // Add API key if provided\n if (config.apiKey) {\n this.defaultHeaders['Authorization'] = `Bearer ${config.apiKey}`;\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 url.searchParams.append(key, value);\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 // 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 throw InsForgeError.fromApiError(data as ApiError);\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 if (token) {\n this.defaultHeaders['Authorization'] = `Bearer ${token}`;\n } else {\n delete this.defaultHeaders['Authorization'];\n }\n }\n\n getHeaders(): Record<string, string> {\n return { ...this.defaultHeaders };\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 for InsForge SDK\n * Supabase-style query builder for PostgREST operations\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\n\nexport interface DatabaseResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n count?: number;\n}\n\n/**\n * Query builder for database operations\n * Uses method chaining like Supabase\n */\nexport class QueryBuilder<T = any> {\n private method: 'GET' | 'POST' | 'PATCH' | 'DELETE' = 'GET';\n private headers: Record<string, string> = {};\n private queryParams: Record<string, string> = {};\n private body?: any;\n\n constructor(\n private table: string,\n private http: HttpClient\n ) {}\n\n /**\n * Perform a SELECT query\n * For mutations (insert/update/delete), this enables returning data\n * @param columns - Columns to select (default: '*')\n * @example\n * .select('*')\n * .select('id, title, content')\n * .select('*, users!inner(*)') // Join with users table\n * .select('*, profile:profiles(*)') // Join with alias\n * .insert({ title: 'New' }).select() // Returns inserted data\n */\n select(columns: string = '*'): this {\n // For mutations, add return=representation header\n if (this.method !== 'GET') {\n const existingPrefer = this.headers['Prefer'] || '';\n const preferParts = existingPrefer ? [existingPrefer] : [];\n if (!preferParts.some(p => p.includes('return='))) {\n preferParts.push('return=representation');\n }\n this.headers['Prefer'] = preferParts.join(',');\n }\n \n // Always set the select parameter for GET requests\n // This enables PostgREST joins and nested queries\n if (this.method === 'GET' && columns) {\n this.queryParams.select = columns;\n } else if (columns !== '*') {\n // For mutations, only set if not default\n this.queryParams.select = columns;\n }\n return this;\n }\n\n /**\n * Perform an INSERT\n * @param values - Single object or array of objects\n * @param options - { upsert: true } for upsert behavior\n * @example\n * .insert({ title: 'Hello', content: 'World' }).select()\n * .insert([{ title: 'Post 1' }, { title: 'Post 2' }]).select()\n */\n insert(values: Partial<T> | Partial<T>[], options?: { upsert?: boolean }): this {\n this.method = 'POST';\n this.body = Array.isArray(values) ? values : [values];\n \n if (options?.upsert) {\n this.headers['Prefer'] = 'resolution=merge-duplicates';\n }\n \n return this;\n }\n\n /**\n * Perform an UPDATE\n * @param values - Object with fields to update\n * @example\n * .update({ title: 'Updated Title' }).select()\n */\n update(values: Partial<T>): this {\n this.method = 'PATCH';\n this.body = values;\n return this;\n }\n\n /**\n * Perform a DELETE\n * @example\n * .delete().select()\n */\n delete(): this {\n this.method = 'DELETE';\n return this;\n }\n\n /**\n * Perform an UPSERT\n * @param values - Single object or array of objects\n * @example\n * .upsert({ id: 1, title: 'Hello' })\n */\n upsert(values: Partial<T> | Partial<T>[]): this {\n return this.insert(values, { upsert: true });\n }\n\n // FILTERS\n\n /**\n * Filter by column equal to value\n * @example .eq('id', 123)\n */\n eq(column: string, value: any): this {\n this.queryParams[column] = `eq.${value}`;\n return this;\n }\n\n /**\n * Filter by column not equal to value\n * @example .neq('status', 'draft')\n */\n neq(column: string, value: any): this {\n this.queryParams[column] = `neq.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than value\n * @example .gt('age', 18)\n */\n gt(column: string, value: any): this {\n this.queryParams[column] = `gt.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than or equal to value\n * @example .gte('price', 100)\n */\n gte(column: string, value: any): this {\n this.queryParams[column] = `gte.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than value\n * @example .lt('stock', 10)\n */\n lt(column: string, value: any): this {\n this.queryParams[column] = `lt.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than or equal to value\n * @example .lte('discount', 50)\n */\n lte(column: string, value: any): this {\n this.queryParams[column] = `lte.${value}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-sensitive)\n * @example .like('email', '%@gmail.com')\n */\n like(column: string, pattern: string): this {\n this.queryParams[column] = `like.${pattern}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-insensitive)\n * @example .ilike('name', '%john%')\n */\n ilike(column: string, pattern: string): this {\n this.queryParams[column] = `ilike.${pattern}`;\n return this;\n }\n\n /**\n * Filter by checking if column is a value\n * @example .is('deleted_at', null)\n */\n is(column: string, value: null | boolean): this {\n if (value === null) {\n this.queryParams[column] = 'is.null';\n } else {\n this.queryParams[column] = `is.${value}`;\n }\n return this;\n }\n\n /**\n * Filter by checking if value is in array\n * @example .in('status', ['active', 'pending'])\n */\n in(column: string, values: any[]): this {\n this.queryParams[column] = `in.(${values.join(',')})`;\n return this;\n }\n\n // MODIFIERS\n\n /**\n * Order by column\n * @example \n * .order('created_at') // ascending\n * .order('created_at', { ascending: false }) // descending\n */\n order(column: string, options?: { ascending?: boolean }): this {\n const ascending = options?.ascending !== false;\n this.queryParams.order = ascending ? column : `${column}.desc`;\n return this;\n }\n\n /**\n * Limit the number of rows returned\n * @example .limit(10)\n */\n limit(count: number): this {\n this.queryParams.limit = count.toString();\n return this;\n }\n\n /**\n * Return results from an offset\n * @example .offset(20)\n */\n offset(count: number): this {\n this.queryParams.offset = count.toString();\n return this;\n }\n\n /**\n * Set a range of rows to return\n * @example .range(0, 9) // First 10 rows\n */\n range(from: number, to: number): this {\n this.headers['Range'] = `${from}-${to}`;\n return this;\n }\n\n /**\n * Return a single object instead of array\n * @example .single()\n */\n single(): this {\n this.headers['Accept'] = 'application/vnd.pgrst.object+json';\n return this;\n }\n\n /**\n * Get the total count (use with select)\n * @example .select('*', { count: 'exact' })\n */\n count(algorithm: 'exact' | 'planned' | 'estimated' = 'exact'): this {\n const prefer = this.headers['Prefer'] || '';\n this.headers['Prefer'] = prefer ? `${prefer},count=${algorithm}` : `count=${algorithm}`;\n return this;\n }\n\n /**\n * Execute the query and return results\n */\n async execute(): Promise<DatabaseResponse<T>> {\n try {\n const path = `/api/database/records/${this.table}`;\n let response: any;\n\n switch (this.method) {\n case 'GET':\n response = await this.http.get<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'POST':\n response = await this.http.post<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'PATCH':\n response = await this.http.patch<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'DELETE':\n response = await this.http.delete<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\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 'Database operation failed',\n 500,\n 'DATABASE_ERROR'\n )\n };\n }\n }\n\n /**\n * Make QueryBuilder thenable for async/await\n */\n then<TResult1 = DatabaseResponse<T>, TResult2 = never>(\n onfulfilled?: ((value: DatabaseResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): Promise<TResult1 | TResult2> {\n return this.execute().then(onfulfilled, onrejected);\n }\n}\n\n/**\n * Database client for InsForge SDK\n * Provides Supabase-style interface\n */\nexport class Database {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a query builder for a table\n * @param table - The table name\n * @example\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId)\n * .order('created_at', { ascending: false })\n * .limit(10);\n */\n from<T = any>(table: string): QueryBuilder<T> {\n return new QueryBuilder<T>(table, this.http);\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';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\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);\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: 'google' | 'github';\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: InsForgeError | 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 if (profileError && profileError.statusCode !== 406) { // 406 = 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: InsForgeError | 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.statusCode === 406) {\n return { data: null, error: null };\n }\n \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 async getCurrentSession(): Promise<{\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: InsForgeError | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.user?.id) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n\n // Update the profile using query builder\n return await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\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\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 * @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 const formData = new FormData();\n formData.append('file', file);\n\n // Use PUT for specific path\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 } 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 * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const formData = new FormData();\n formData.append('file', file);\n\n // Use POST for auto-generated key\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 } 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 * Download a file\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 // For binary data, we need to use fetch directly with proper response handling\n // The http.request method expects JSON responses, so we can't use it for blobs\n const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n \n const response = await this.http.fetch(url, {\n method: 'GET',\n headers: this.http.getHeaders()\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}","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';\nimport { Storage } from './modules/storage';\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 */\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\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http);\n this.storage = new Storage(this.http);\n }\n\n\n /**\n * Set a custom API key for authentication\n * This is useful for server-to-server communication\n * \n * @param apiKey - The API key (should start with 'ik_')\n * \n * @example\n * ```typescript\n * client.setApiKey('ik_your_api_key_here');\n * ```\n */\n setApiKey(apiKey: string): void {\n // API keys can be used as Bearer tokens\n this.http.setAuthToken(apiKey);\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;;;ACmEO,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;AA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I;AAAA,EAChD;AACF;;;AC3LO,IAAM,iBAAN,MAAqB;AAAA,EAQ1B,YAAY,SAAyB,CAAC,GAAG;AACvC,SAAK,OAAO,IAAI,WAAW,MAAM;AACjC,SAAK,eAAe,IAAI,aAAa,OAAO,OAAO;AAEnD,SAAK,OAAO,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAEA,SAAK,WAAW,IAAI,SAAS,KAAK,IAAI;AACtC,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,UAAU,QAAsB;AAE9B,SAAK,KAAK,aAAa,MAAM;AAAA,EAC/B;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;;;APpDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":[]}
package/dist/index.mjs CHANGED
@@ -725,101 +725,11 @@ var StorageBucket = class {
725
725
  this.http = http;
726
726
  }
727
727
  /**
728
- * Upload a file with a specific key using the appropriate strategy
728
+ * Upload a file with a specific key
729
729
  * @param path - The object key/path
730
730
  * @param file - File or Blob to upload
731
731
  */
732
732
  async upload(path, file) {
733
- try {
734
- const strategyRequest = {
735
- filename: path,
736
- contentType: file.type || "application/octet-stream",
737
- size: file.size
738
- };
739
- const strategy = await this.http.post(
740
- `/api/storage/buckets/${this.bucketName}/upload-strategy`,
741
- strategyRequest
742
- );
743
- if (!strategy) {
744
- throw new InsForgeError("Failed to get upload strategy", 500, "STORAGE_ERROR");
745
- }
746
- if (strategy.method === "presigned") {
747
- return await this.uploadPresigned(strategy, file);
748
- } else {
749
- return await this.uploadDirect(path, file);
750
- }
751
- } catch (error) {
752
- return {
753
- data: null,
754
- error: error instanceof InsForgeError ? error : new InsForgeError(
755
- "Upload failed",
756
- 500,
757
- "STORAGE_ERROR"
758
- )
759
- };
760
- }
761
- }
762
- /**
763
- * Upload using presigned URL (for S3)
764
- */
765
- async uploadPresigned(strategy, file) {
766
- try {
767
- const formData = new FormData();
768
- if (strategy.fields) {
769
- Object.entries(strategy.fields).forEach(([key, value]) => {
770
- formData.append(key, value);
771
- });
772
- }
773
- formData.append("file", file);
774
- const uploadResponse = await fetch(strategy.uploadUrl, {
775
- method: "POST",
776
- body: formData
777
- });
778
- if (!uploadResponse.ok) {
779
- const text = await uploadResponse.text();
780
- throw new InsForgeError(
781
- `Presigned upload failed: ${text}`,
782
- uploadResponse.status,
783
- "STORAGE_ERROR"
784
- );
785
- }
786
- if (strategy.confirmRequired && strategy.confirmUrl) {
787
- const confirmRequest = {
788
- size: file.size,
789
- contentType: file.type || "application/octet-stream"
790
- };
791
- const confirmResponse = await this.http.post(
792
- strategy.confirmUrl,
793
- confirmRequest
794
- );
795
- return { data: confirmResponse, error: null };
796
- }
797
- return {
798
- data: {
799
- bucket: this.bucketName,
800
- key: strategy.key,
801
- size: file.size,
802
- mimeType: file.type,
803
- uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
804
- url: this.getPublicUrl(strategy.key)
805
- },
806
- error: null
807
- };
808
- } catch (error) {
809
- return {
810
- data: null,
811
- error: error instanceof InsForgeError ? error : new InsForgeError(
812
- "Presigned upload failed",
813
- 500,
814
- "STORAGE_ERROR"
815
- )
816
- };
817
- }
818
- }
819
- /**
820
- * Upload directly to backend (for local storage)
821
- */
822
- async uploadDirect(path, file) {
823
733
  try {
824
734
  const formData = new FormData();
825
735
  formData.append("file", file);
@@ -838,7 +748,7 @@ var StorageBucket = class {
838
748
  return {
839
749
  data: null,
840
750
  error: error instanceof InsForgeError ? error : new InsForgeError(
841
- "Direct upload failed",
751
+ "Upload failed",
842
752
  500,
843
753
  "STORAGE_ERROR"
844
754
  )
@@ -876,78 +786,11 @@ var StorageBucket = class {
876
786
  }
877
787
  }
878
788
  /**
879
- * Download a file using the appropriate strategy
789
+ * Download a file
880
790
  * @param path - The object key/path
881
791
  * Returns the file as a Blob
882
792
  */
883
793
  async download(path) {
884
- try {
885
- const strategyRequest = {
886
- expiresIn: 3600
887
- // 1 hour default
888
- };
889
- const strategy = await this.http.post(
890
- `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,
891
- strategyRequest
892
- );
893
- if (!strategy) {
894
- return await this.downloadDirect(path);
895
- }
896
- if (strategy.method === "presigned") {
897
- return await this.downloadPresigned(strategy);
898
- } else {
899
- return await this.downloadDirect(path);
900
- }
901
- } catch (error) {
902
- return {
903
- data: null,
904
- error: error instanceof InsForgeError ? error : new InsForgeError(
905
- "Download failed",
906
- 500,
907
- "STORAGE_ERROR"
908
- )
909
- };
910
- }
911
- }
912
- /**
913
- * Download using presigned URL (for S3)
914
- */
915
- async downloadPresigned(strategy) {
916
- try {
917
- const headers = {};
918
- if (strategy.headers) {
919
- Object.entries(strategy.headers).forEach(([key, value]) => {
920
- headers[key] = value;
921
- });
922
- }
923
- const response = await fetch(strategy.url, {
924
- method: "GET",
925
- headers
926
- });
927
- if (!response.ok) {
928
- throw new InsForgeError(
929
- `Download failed: ${response.statusText}`,
930
- response.status,
931
- "STORAGE_ERROR"
932
- );
933
- }
934
- const blob = await response.blob();
935
- return { data: blob, error: null };
936
- } catch (error) {
937
- return {
938
- data: null,
939
- error: error instanceof InsForgeError ? error : new InsForgeError(
940
- "Presigned download failed",
941
- 500,
942
- "STORAGE_ERROR"
943
- )
944
- };
945
- }
946
- }
947
- /**
948
- * Download directly from backend (for local storage)
949
- */
950
- async downloadDirect(path) {
951
794
  try {
952
795
  const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;
953
796
  const response = await this.http.fetch(url, {
@@ -972,17 +815,15 @@ var StorageBucket = class {
972
815
  return {
973
816
  data: null,
974
817
  error: error instanceof InsForgeError ? error : new InsForgeError(
975
- "Direct download failed",
818
+ "Download failed",
976
819
  500,
977
820
  "STORAGE_ERROR"
978
821
  )
979
822
  };
980
823
  }
981
824
  }
982
- // Removed getSignedUrl - this is handled internally by download()
983
- // The SDK abstracts away presigned URL complexity
984
825
  /**
985
- * Get public URL for a file (direct URL, may not work for private S3)
826
+ * Get public URL for a file
986
827
  * @param path - The object key/path
987
828
  */
988
829
  getPublicUrl(path) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database.ts","../src/modules/auth.ts","../src/modules/storage.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 URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n url?: string;\n\n /**\n * API key (optional)\n * Can be used for server-side operations or specific use cases\n */\n apiKey?: 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\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.url || '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.defaultHeaders = {\n ...config.headers,\n };\n \n // Add API key if provided\n if (config.apiKey) {\n this.defaultHeaders['Authorization'] = `Bearer ${config.apiKey}`;\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 url.searchParams.append(key, value);\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 // 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 throw InsForgeError.fromApiError(data as ApiError);\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 if (token) {\n this.defaultHeaders['Authorization'] = `Bearer ${token}`;\n } else {\n delete this.defaultHeaders['Authorization'];\n }\n }\n\n getHeaders(): Record<string, string> {\n return { ...this.defaultHeaders };\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 for InsForge SDK\n * Supabase-style query builder for PostgREST operations\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\n\nexport interface DatabaseResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n count?: number;\n}\n\n/**\n * Query builder for database operations\n * Uses method chaining like Supabase\n */\nexport class QueryBuilder<T = any> {\n private method: 'GET' | 'POST' | 'PATCH' | 'DELETE' = 'GET';\n private headers: Record<string, string> = {};\n private queryParams: Record<string, string> = {};\n private body?: any;\n\n constructor(\n private table: string,\n private http: HttpClient\n ) {}\n\n /**\n * Perform a SELECT query\n * For mutations (insert/update/delete), this enables returning data\n * @param columns - Columns to select (default: '*')\n * @example\n * .select('*')\n * .select('id, title, content')\n * .select('*, users!inner(*)') // Join with users table\n * .select('*, profile:profiles(*)') // Join with alias\n * .insert({ title: 'New' }).select() // Returns inserted data\n */\n select(columns: string = '*'): this {\n // For mutations, add return=representation header\n if (this.method !== 'GET') {\n const existingPrefer = this.headers['Prefer'] || '';\n const preferParts = existingPrefer ? [existingPrefer] : [];\n if (!preferParts.some(p => p.includes('return='))) {\n preferParts.push('return=representation');\n }\n this.headers['Prefer'] = preferParts.join(',');\n }\n \n // Always set the select parameter for GET requests\n // This enables PostgREST joins and nested queries\n if (this.method === 'GET' && columns) {\n this.queryParams.select = columns;\n } else if (columns !== '*') {\n // For mutations, only set if not default\n this.queryParams.select = columns;\n }\n return this;\n }\n\n /**\n * Perform an INSERT\n * @param values - Single object or array of objects\n * @param options - { upsert: true } for upsert behavior\n * @example\n * .insert({ title: 'Hello', content: 'World' }).select()\n * .insert([{ title: 'Post 1' }, { title: 'Post 2' }]).select()\n */\n insert(values: Partial<T> | Partial<T>[], options?: { upsert?: boolean }): this {\n this.method = 'POST';\n this.body = Array.isArray(values) ? values : [values];\n \n if (options?.upsert) {\n this.headers['Prefer'] = 'resolution=merge-duplicates';\n }\n \n return this;\n }\n\n /**\n * Perform an UPDATE\n * @param values - Object with fields to update\n * @example\n * .update({ title: 'Updated Title' }).select()\n */\n update(values: Partial<T>): this {\n this.method = 'PATCH';\n this.body = values;\n return this;\n }\n\n /**\n * Perform a DELETE\n * @example\n * .delete().select()\n */\n delete(): this {\n this.method = 'DELETE';\n return this;\n }\n\n /**\n * Perform an UPSERT\n * @param values - Single object or array of objects\n * @example\n * .upsert({ id: 1, title: 'Hello' })\n */\n upsert(values: Partial<T> | Partial<T>[]): this {\n return this.insert(values, { upsert: true });\n }\n\n // FILTERS\n\n /**\n * Filter by column equal to value\n * @example .eq('id', 123)\n */\n eq(column: string, value: any): this {\n this.queryParams[column] = `eq.${value}`;\n return this;\n }\n\n /**\n * Filter by column not equal to value\n * @example .neq('status', 'draft')\n */\n neq(column: string, value: any): this {\n this.queryParams[column] = `neq.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than value\n * @example .gt('age', 18)\n */\n gt(column: string, value: any): this {\n this.queryParams[column] = `gt.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than or equal to value\n * @example .gte('price', 100)\n */\n gte(column: string, value: any): this {\n this.queryParams[column] = `gte.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than value\n * @example .lt('stock', 10)\n */\n lt(column: string, value: any): this {\n this.queryParams[column] = `lt.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than or equal to value\n * @example .lte('discount', 50)\n */\n lte(column: string, value: any): this {\n this.queryParams[column] = `lte.${value}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-sensitive)\n * @example .like('email', '%@gmail.com')\n */\n like(column: string, pattern: string): this {\n this.queryParams[column] = `like.${pattern}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-insensitive)\n * @example .ilike('name', '%john%')\n */\n ilike(column: string, pattern: string): this {\n this.queryParams[column] = `ilike.${pattern}`;\n return this;\n }\n\n /**\n * Filter by checking if column is a value\n * @example .is('deleted_at', null)\n */\n is(column: string, value: null | boolean): this {\n if (value === null) {\n this.queryParams[column] = 'is.null';\n } else {\n this.queryParams[column] = `is.${value}`;\n }\n return this;\n }\n\n /**\n * Filter by checking if value is in array\n * @example .in('status', ['active', 'pending'])\n */\n in(column: string, values: any[]): this {\n this.queryParams[column] = `in.(${values.join(',')})`;\n return this;\n }\n\n // MODIFIERS\n\n /**\n * Order by column\n * @example \n * .order('created_at') // ascending\n * .order('created_at', { ascending: false }) // descending\n */\n order(column: string, options?: { ascending?: boolean }): this {\n const ascending = options?.ascending !== false;\n this.queryParams.order = ascending ? column : `${column}.desc`;\n return this;\n }\n\n /**\n * Limit the number of rows returned\n * @example .limit(10)\n */\n limit(count: number): this {\n this.queryParams.limit = count.toString();\n return this;\n }\n\n /**\n * Return results from an offset\n * @example .offset(20)\n */\n offset(count: number): this {\n this.queryParams.offset = count.toString();\n return this;\n }\n\n /**\n * Set a range of rows to return\n * @example .range(0, 9) // First 10 rows\n */\n range(from: number, to: number): this {\n this.headers['Range'] = `${from}-${to}`;\n return this;\n }\n\n /**\n * Return a single object instead of array\n * @example .single()\n */\n single(): this {\n this.headers['Accept'] = 'application/vnd.pgrst.object+json';\n return this;\n }\n\n /**\n * Get the total count (use with select)\n * @example .select('*', { count: 'exact' })\n */\n count(algorithm: 'exact' | 'planned' | 'estimated' = 'exact'): this {\n const prefer = this.headers['Prefer'] || '';\n this.headers['Prefer'] = prefer ? `${prefer},count=${algorithm}` : `count=${algorithm}`;\n return this;\n }\n\n /**\n * Execute the query and return results\n */\n async execute(): Promise<DatabaseResponse<T>> {\n try {\n const path = `/api/database/records/${this.table}`;\n let response: any;\n\n switch (this.method) {\n case 'GET':\n response = await this.http.get<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'POST':\n response = await this.http.post<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'PATCH':\n response = await this.http.patch<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'DELETE':\n response = await this.http.delete<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\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 'Database operation failed',\n 500,\n 'DATABASE_ERROR'\n )\n };\n }\n }\n\n /**\n * Make QueryBuilder thenable for async/await\n */\n then<TResult1 = DatabaseResponse<T>, TResult2 = never>(\n onfulfilled?: ((value: DatabaseResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): Promise<TResult1 | TResult2> {\n return this.execute().then(onfulfilled, onrejected);\n }\n}\n\n/**\n * Database client for InsForge SDK\n * Provides Supabase-style interface\n */\nexport class Database {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a query builder for a table\n * @param table - The table name\n * @example\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId)\n * .order('created_at', { ascending: false })\n * .limit(10);\n */\n from<T = any>(table: string): QueryBuilder<T> {\n return new QueryBuilder<T>(table, this.http);\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';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\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);\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: 'google' | 'github';\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: InsForgeError | 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 if (profileError && profileError.statusCode !== 406) { // 406 = 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: InsForgeError | 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.statusCode === 406) {\n return { data: null, error: null };\n }\n \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 async getCurrentSession(): Promise<{\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: InsForgeError | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.user?.id) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n\n // Update the profile using query builder\n return await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n * Supports both presigned URLs (S3) and direct uploads (local)\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema,\n UploadStrategyRequest,\n UploadStrategyResponse,\n DownloadStrategyRequest,\n DownloadStrategyResponse,\n ConfirmUploadRequest\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\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 using the appropriate strategy\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 // Step 1: Get upload strategy from backend\n const strategyRequest: UploadStrategyRequest = {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n };\n\n const strategy = await this.http.post<UploadStrategyResponse>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n strategyRequest\n );\n \n if (!strategy) {\n throw new InsForgeError('Failed to get upload strategy', 500, 'STORAGE_ERROR');\n }\n\n // Step 2: Upload based on strategy\n if (strategy.method === 'presigned') {\n return await this.uploadPresigned(strategy, file);\n } else {\n return await this.uploadDirect(path, file);\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 using presigned URL (for S3)\n */\n private async uploadPresigned(\n strategy: UploadStrategyResponse,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Step 1: Upload to presigned URL\n const formData = new FormData();\n \n // Add any fields from the strategy (S3 requires these)\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be added last for S3\n formData.append('file', file);\n\n // Upload directly to S3 (or presigned URL)\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n const text = await uploadResponse.text();\n throw new InsForgeError(\n `Presigned upload failed: ${text}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Step 2: Confirm upload with backend\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmRequest: ConfirmUploadRequest = {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n };\n\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n confirmRequest\n );\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, construct response\n return {\n data: {\n bucket: this.bucketName,\n key: strategy.key,\n size: file.size,\n mimeType: file.type,\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n },\n error: null\n };\n } catch (error) {\n return {\n data: null,\n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload directly to backend (for local storage)\n */\n private async uploadDirect(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const formData = new FormData();\n formData.append('file', file);\n\n // Use PUT for specific path\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 } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Direct upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // For auto-generated keys, always use POST directly to backend\n // The backend will handle the strategy internally\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 } 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 * Download a file using the appropriate strategy\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 // Step 1: Get download strategy from backend\n const strategyRequest: DownloadStrategyRequest = {\n expiresIn: 3600 // 1 hour default\n };\n\n const strategy = await this.http.post<DownloadStrategyResponse>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n strategyRequest\n );\n \n if (!strategy) {\n // Fallback to direct download\n return await this.downloadDirect(path);\n }\n\n // Step 2: Download based on strategy\n if (strategy.method === 'presigned') {\n return await this.downloadPresigned(strategy);\n } else {\n return await this.downloadDirect(path);\n }\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 * Download using presigned URL (for S3)\n */\n private async downloadPresigned(\n strategy: DownloadStrategyResponse\n ): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n const headers: HeadersInit = {};\n \n // Add any headers from the strategy\n if (strategy.headers) {\n Object.entries(strategy.headers).forEach(([key, value]) => {\n headers[key] = value;\n });\n }\n\n const response = await fetch(strategy.url, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\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 'Presigned download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Download directly from backend (for local storage)\n */\n private async downloadDirect(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n \n const response = await this.http.fetch(url, {\n method: 'GET',\n headers: this.http.getHeaders()\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 'Direct download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n // Removed getSignedUrl - this is handled internally by download()\n // The SDK abstracts away presigned URL complexity\n\n /**\n * Get public URL for a file (direct URL, may not work for private S3)\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}","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';\nimport { Storage } from './modules/storage';\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 */\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\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http);\n this.storage = new Storage(this.http);\n }\n\n\n /**\n * Set a custom API key for authentication\n * This is useful for server-to-server communication\n * \n * @param apiKey - The API key (should start with 'ik_')\n * \n * @example\n * ```typescript\n * client.setApiKey('ik_your_api_key_here');\n * ```\n */\n setApiKey(apiKey: string): void {\n // API keys can be used as Bearer tokens\n this.http.setAuthToken(apiKey);\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 and types\nexport { Database, QueryBuilder } from './modules/database';\nexport type { DatabaseResponse } from './modules/database';\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\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":";AAmEO,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;;;AClFO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAY,Q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AO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;ACpDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database.ts","../src/modules/auth.ts","../src/modules/storage.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 URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n url?: string;\n\n /**\n * API key (optional)\n * Can be used for server-side operations or specific use cases\n */\n apiKey?: 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\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.url || '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.defaultHeaders = {\n ...config.headers,\n };\n \n // Add API key if provided\n if (config.apiKey) {\n this.defaultHeaders['Authorization'] = `Bearer ${config.apiKey}`;\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 url.searchParams.append(key, value);\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 // 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 throw InsForgeError.fromApiError(data as ApiError);\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 if (token) {\n this.defaultHeaders['Authorization'] = `Bearer ${token}`;\n } else {\n delete this.defaultHeaders['Authorization'];\n }\n }\n\n getHeaders(): Record<string, string> {\n return { ...this.defaultHeaders };\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 for InsForge SDK\n * Supabase-style query builder for PostgREST operations\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\n\nexport interface DatabaseResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n count?: number;\n}\n\n/**\n * Query builder for database operations\n * Uses method chaining like Supabase\n */\nexport class QueryBuilder<T = any> {\n private method: 'GET' | 'POST' | 'PATCH' | 'DELETE' = 'GET';\n private headers: Record<string, string> = {};\n private queryParams: Record<string, string> = {};\n private body?: any;\n\n constructor(\n private table: string,\n private http: HttpClient\n ) {}\n\n /**\n * Perform a SELECT query\n * For mutations (insert/update/delete), this enables returning data\n * @param columns - Columns to select (default: '*')\n * @example\n * .select('*')\n * .select('id, title, content')\n * .select('*, users!inner(*)') // Join with users table\n * .select('*, profile:profiles(*)') // Join with alias\n * .insert({ title: 'New' }).select() // Returns inserted data\n */\n select(columns: string = '*'): this {\n // For mutations, add return=representation header\n if (this.method !== 'GET') {\n const existingPrefer = this.headers['Prefer'] || '';\n const preferParts = existingPrefer ? [existingPrefer] : [];\n if (!preferParts.some(p => p.includes('return='))) {\n preferParts.push('return=representation');\n }\n this.headers['Prefer'] = preferParts.join(',');\n }\n \n // Always set the select parameter for GET requests\n // This enables PostgREST joins and nested queries\n if (this.method === 'GET' && columns) {\n this.queryParams.select = columns;\n } else if (columns !== '*') {\n // For mutations, only set if not default\n this.queryParams.select = columns;\n }\n return this;\n }\n\n /**\n * Perform an INSERT\n * @param values - Single object or array of objects\n * @param options - { upsert: true } for upsert behavior\n * @example\n * .insert({ title: 'Hello', content: 'World' }).select()\n * .insert([{ title: 'Post 1' }, { title: 'Post 2' }]).select()\n */\n insert(values: Partial<T> | Partial<T>[], options?: { upsert?: boolean }): this {\n this.method = 'POST';\n this.body = Array.isArray(values) ? values : [values];\n \n if (options?.upsert) {\n this.headers['Prefer'] = 'resolution=merge-duplicates';\n }\n \n return this;\n }\n\n /**\n * Perform an UPDATE\n * @param values - Object with fields to update\n * @example\n * .update({ title: 'Updated Title' }).select()\n */\n update(values: Partial<T>): this {\n this.method = 'PATCH';\n this.body = values;\n return this;\n }\n\n /**\n * Perform a DELETE\n * @example\n * .delete().select()\n */\n delete(): this {\n this.method = 'DELETE';\n return this;\n }\n\n /**\n * Perform an UPSERT\n * @param values - Single object or array of objects\n * @example\n * .upsert({ id: 1, title: 'Hello' })\n */\n upsert(values: Partial<T> | Partial<T>[]): this {\n return this.insert(values, { upsert: true });\n }\n\n // FILTERS\n\n /**\n * Filter by column equal to value\n * @example .eq('id', 123)\n */\n eq(column: string, value: any): this {\n this.queryParams[column] = `eq.${value}`;\n return this;\n }\n\n /**\n * Filter by column not equal to value\n * @example .neq('status', 'draft')\n */\n neq(column: string, value: any): this {\n this.queryParams[column] = `neq.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than value\n * @example .gt('age', 18)\n */\n gt(column: string, value: any): this {\n this.queryParams[column] = `gt.${value}`;\n return this;\n }\n\n /**\n * Filter by column greater than or equal to value\n * @example .gte('price', 100)\n */\n gte(column: string, value: any): this {\n this.queryParams[column] = `gte.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than value\n * @example .lt('stock', 10)\n */\n lt(column: string, value: any): this {\n this.queryParams[column] = `lt.${value}`;\n return this;\n }\n\n /**\n * Filter by column less than or equal to value\n * @example .lte('discount', 50)\n */\n lte(column: string, value: any): this {\n this.queryParams[column] = `lte.${value}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-sensitive)\n * @example .like('email', '%@gmail.com')\n */\n like(column: string, pattern: string): this {\n this.queryParams[column] = `like.${pattern}`;\n return this;\n }\n\n /**\n * Filter by pattern matching (case-insensitive)\n * @example .ilike('name', '%john%')\n */\n ilike(column: string, pattern: string): this {\n this.queryParams[column] = `ilike.${pattern}`;\n return this;\n }\n\n /**\n * Filter by checking if column is a value\n * @example .is('deleted_at', null)\n */\n is(column: string, value: null | boolean): this {\n if (value === null) {\n this.queryParams[column] = 'is.null';\n } else {\n this.queryParams[column] = `is.${value}`;\n }\n return this;\n }\n\n /**\n * Filter by checking if value is in array\n * @example .in('status', ['active', 'pending'])\n */\n in(column: string, values: any[]): this {\n this.queryParams[column] = `in.(${values.join(',')})`;\n return this;\n }\n\n // MODIFIERS\n\n /**\n * Order by column\n * @example \n * .order('created_at') // ascending\n * .order('created_at', { ascending: false }) // descending\n */\n order(column: string, options?: { ascending?: boolean }): this {\n const ascending = options?.ascending !== false;\n this.queryParams.order = ascending ? column : `${column}.desc`;\n return this;\n }\n\n /**\n * Limit the number of rows returned\n * @example .limit(10)\n */\n limit(count: number): this {\n this.queryParams.limit = count.toString();\n return this;\n }\n\n /**\n * Return results from an offset\n * @example .offset(20)\n */\n offset(count: number): this {\n this.queryParams.offset = count.toString();\n return this;\n }\n\n /**\n * Set a range of rows to return\n * @example .range(0, 9) // First 10 rows\n */\n range(from: number, to: number): this {\n this.headers['Range'] = `${from}-${to}`;\n return this;\n }\n\n /**\n * Return a single object instead of array\n * @example .single()\n */\n single(): this {\n this.headers['Accept'] = 'application/vnd.pgrst.object+json';\n return this;\n }\n\n /**\n * Get the total count (use with select)\n * @example .select('*', { count: 'exact' })\n */\n count(algorithm: 'exact' | 'planned' | 'estimated' = 'exact'): this {\n const prefer = this.headers['Prefer'] || '';\n this.headers['Prefer'] = prefer ? `${prefer},count=${algorithm}` : `count=${algorithm}`;\n return this;\n }\n\n /**\n * Execute the query and return results\n */\n async execute(): Promise<DatabaseResponse<T>> {\n try {\n const path = `/api/database/records/${this.table}`;\n let response: any;\n\n switch (this.method) {\n case 'GET':\n response = await this.http.get<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'POST':\n response = await this.http.post<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'PATCH':\n response = await this.http.patch<T>(path, this.body, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\n \n case 'DELETE':\n response = await this.http.delete<T>(path, {\n params: this.queryParams,\n headers: this.headers\n });\n break;\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 'Database operation failed',\n 500,\n 'DATABASE_ERROR'\n )\n };\n }\n }\n\n /**\n * Make QueryBuilder thenable for async/await\n */\n then<TResult1 = DatabaseResponse<T>, TResult2 = never>(\n onfulfilled?: ((value: DatabaseResponse<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): Promise<TResult1 | TResult2> {\n return this.execute().then(onfulfilled, onrejected);\n }\n}\n\n/**\n * Database client for InsForge SDK\n * Provides Supabase-style interface\n */\nexport class Database {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a query builder for a table\n * @param table - The table name\n * @example\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId)\n * .order('created_at', { ascending: false })\n * .limit(10);\n */\n from<T = any>(table: string): QueryBuilder<T> {\n return new QueryBuilder<T>(table, this.http);\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';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\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);\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: 'google' | 'github';\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: InsForgeError | 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 if (profileError && profileError.statusCode !== 406) { // 406 = 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: InsForgeError | 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.statusCode === 406) {\n return { data: null, error: null };\n }\n \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 async getCurrentSession(): Promise<{\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: InsForgeError | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.user?.id) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n\n // Update the profile using query builder\n return await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\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\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 * @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 const formData = new FormData();\n formData.append('file', file);\n\n // Use PUT for specific path\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 } 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 * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const formData = new FormData();\n formData.append('file', file);\n\n // Use POST for auto-generated key\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 } 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 * Download a file\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 // For binary data, we need to use fetch directly with proper response handling\n // The http.request method expects JSON responses, so we can't use it for blobs\n const url = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n \n const response = await this.http.fetch(url, {\n method: 'GET',\n headers: this.http.getHeaders()\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}","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';\nimport { Storage } from './modules/storage';\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 */\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\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http);\n this.storage = new Storage(this.http);\n }\n\n\n /**\n * Set a custom API key for authentication\n * This is useful for server-to-server communication\n * \n * @param apiKey - The API key (should start with 'ik_')\n * \n * @example\n * ```typescript\n * client.setApiKey('ik_your_api_key_here');\n * ```\n */\n setApiKey(apiKey: string): void {\n // API keys can be used as Bearer tokens\n this.http.setAuthToken(apiKey);\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 and types\nexport { Database, QueryBuilder } from './modules/database';\nexport type { DatabaseResponse } from './modules/database';\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\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":";AAmEO,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;;;AClFO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAY,QAAwB;AAClC,SAAK,UAAU,OAAO,OAAO;AAE7B,SAAK,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM,KAAK,UAAU,IAAI;AACrF,SAAK,iBAAiB;AAAA,MACpB,GAAG,OAAO;AAAA,IACZ;AAGA,QAAI,OAAO,QAAQ;AACjB,WAAK,eAAe,eAAe,IAAI,UAAU,OAAO,MAAM;AAAA,IAChE;AAEA,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI;AAAA,QACR;AA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AAsB;AAE9B,SAAK,KAAK,aAAa,MAAM;AAAA,EAC/B;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;;;ACpDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/sdk",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "TypeScript SDK for InsForge Backend-as-a-Service platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",