chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,283 @@
|
||||
1. Add InsForge dependencies to your project
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Maven Central">
|
||||
build.gradle.kts:
|
||||
```kotlin
|
||||
repositories {
|
||||
mavenLocal() // For local development
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("dev.insforge:insforge-kotlin:0.1.6")
|
||||
}
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="GitHub Packages">
|
||||
First, create a GitHub Personal Access Token:
|
||||
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
|
||||
- Select permission: `read:packages`
|
||||
|
||||
Then configure your project using one of the following methods:
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Option A: Environment Variables">
|
||||
settings.gradle.kts (or build.gradle.kts):
|
||||
```kotlin
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://maven.pkg.github.com/InsForge/insforge-kotlin")
|
||||
credentials {
|
||||
username = System.getenv("GITHUB_USER") ?: ""
|
||||
password = System.getenv("GITHUB_TOKEN") ?: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
build.gradle.kts:
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("dev.insforge:insforge-kotlin:0.1.6")
|
||||
}
|
||||
```
|
||||
|
||||
Set environment variables before building:
|
||||
```bash
|
||||
export GITHUB_USER="your-github-username"
|
||||
export GITHUB_TOKEN="your-personal-access-token"
|
||||
```
|
||||
</Accordion>
|
||||
<Accordion title="Option B: gradle.properties (Local Development)">
|
||||
Add credentials to your global Gradle properties file:
|
||||
|
||||
~/.gradle/gradle.properties:
|
||||
```properties
|
||||
gpr.user=your-github-username
|
||||
gpr.token=ghp_xxxxxxxxxxxx
|
||||
```
|
||||
|
||||
settings.gradle.kts:
|
||||
```kotlin
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://maven.pkg.github.com/InsForge/insforge-kotlin")
|
||||
credentials {
|
||||
username = providers.gradleProperty("gpr.user").orNull ?: ""
|
||||
password = providers.gradleProperty("gpr.token").orNull ?: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
build.gradle.kts:
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("dev.insforge:insforge-kotlin:0.1.6")
|
||||
}
|
||||
```
|
||||
|
||||
<Note>
|
||||
The `~/.gradle/gradle.properties` file is stored outside your project, so credentials won't be accidentally committed to version control.
|
||||
</Note>
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
2. Initialize InsForge SDK
|
||||
|
||||
```kotlin
|
||||
import dev.insforge.createInsforgeClient
|
||||
import dev.insforge.auth.Auth
|
||||
import dev.insforge.database.Database
|
||||
import dev.insforge.storage.Storage
|
||||
import dev.insforge.functions.Functions
|
||||
import dev.insforge.realtime.Realtime
|
||||
import dev.insforge.ai.AI
|
||||
|
||||
val client = createInsforgeClient(
|
||||
baseUrl = "https://your-app.insforge.app",
|
||||
anonKey = "your-api-key"
|
||||
) {
|
||||
install(Auth)
|
||||
install(Database)
|
||||
install(Storage)
|
||||
install(Functions)
|
||||
install(Realtime) {
|
||||
autoReconnect = true
|
||||
reconnectDelay = 5000
|
||||
}
|
||||
install(AI)
|
||||
}
|
||||
```
|
||||
|
||||
3. Enable Logging (Optional)
|
||||
|
||||
For debugging, you can configure the SDK log level:
|
||||
|
||||
```kotlin
|
||||
import dev.insforge.InsforgeLogLevel
|
||||
|
||||
val client = createInsforgeClient(
|
||||
baseUrl = "https://your-app.insforge.app",
|
||||
anonKey = "your-api-key"
|
||||
) {
|
||||
// DEBUG: logs request method/URL and response status
|
||||
// VERBOSE: logs full headers and request/response bodies
|
||||
logLevel = InsforgeLogLevel.DEBUG
|
||||
|
||||
install(Auth)
|
||||
install(Database)
|
||||
// ... other modules
|
||||
}
|
||||
```
|
||||
|
||||
| Log Level | Description |
|
||||
|-----------|-------------|
|
||||
| `NONE` | No logging (default, recommended for production) |
|
||||
| `ERROR` | Only errors |
|
||||
| `WARN` | Warnings and errors |
|
||||
| `INFO` | Informational messages |
|
||||
| `DEBUG` | Debug info (request method, URL, response status) |
|
||||
| `VERBOSE` | Full details (headers, request/response bodies) |
|
||||
|
||||
<Note>
|
||||
Use `NONE` or `ERROR` in production to avoid exposing sensitive data in logs.
|
||||
</Note>
|
||||
|
||||
### Android Initialization
|
||||
|
||||
1. Add Chrome Custom Tabs dependency to your `build.gradle.kts`:
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("androidx.browser:browser:1.9.0")
|
||||
}
|
||||
```
|
||||
|
||||
2. Initialize InsForge SDK (With Chrome Custom Tabs and Session Storage)
|
||||
|
||||
```kotlin
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import dev.insforge.createInsforgeClient
|
||||
import dev.insforge.ai.AI
|
||||
import dev.insforge.auth.Auth
|
||||
import dev.insforge.auth.BrowserLauncher
|
||||
import dev.insforge.auth.ClientType
|
||||
import dev.insforge.auth.SessionStorage
|
||||
import dev.insforge.database.Database
|
||||
import dev.insforge.functions.Functions
|
||||
import dev.insforge.realtime.Realtime
|
||||
import dev.insforge.storage.Storage
|
||||
|
||||
class InsforgeManager(private val context: Context) {
|
||||
|
||||
val client = createInsforgeClient(
|
||||
baseUrl = "https://your-app.insforge.app",
|
||||
anonKey = "your-anon-key"
|
||||
) {
|
||||
install(Auth) {
|
||||
// 1. Chrome Custom Tabs - opens in-app, similar to iOS ASWebAuthenticationSession
|
||||
browserLauncher = BrowserLauncher { url ->
|
||||
val customTabsIntent = CustomTabsIntent.Builder()
|
||||
.setShowTitle(true)
|
||||
.build()
|
||||
// Handle non-Activity context safely
|
||||
if (context is Activity) {
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
||||
} else {
|
||||
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url))
|
||||
}
|
||||
}
|
||||
|
||||
// 2. enable session persistence
|
||||
persistSession = true
|
||||
|
||||
// 3. config SessionStorage (use SharedPreferences)
|
||||
sessionStorage = object : SessionStorage {
|
||||
private val prefs = context.getSharedPreferences(
|
||||
"insforge_auth",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
override suspend fun save(key: String, value: String) {
|
||||
prefs.edit().putString(key, value).apply()
|
||||
}
|
||||
|
||||
override suspend fun get(key: String): String? {
|
||||
return prefs.getString(key, null)
|
||||
}
|
||||
|
||||
override suspend fun remove(key: String) {
|
||||
prefs.edit().remove(key).apply()
|
||||
}
|
||||
}
|
||||
|
||||
// 4. set client type for mobile
|
||||
clientType = ClientType.MOBILE
|
||||
}
|
||||
// Install Database module
|
||||
install(Database)
|
||||
|
||||
// Install Realtime module for real-time subscriptions
|
||||
install(Realtime) {
|
||||
debug = true
|
||||
}
|
||||
// Install other modules
|
||||
install(Storage)
|
||||
install(Functions)
|
||||
install(AI)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Use Jetpack DataStore for Session Storage (Optional)
|
||||
|
||||
```kotlin
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
val Context.authDataStore: DataStore<Preferences> by preferencesDataStore(name = "insforge_auth")
|
||||
|
||||
class DataStoreSessionStorage(private val context: Context) : SessionStorage {
|
||||
|
||||
override suspend fun save(key: String, value: String) {
|
||||
context.authDataStore.edit { prefs ->
|
||||
prefs[stringPreferencesKey(key)] = value
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun get(key: String): String? {
|
||||
return context.authDataStore.data.map { prefs ->
|
||||
prefs[stringPreferencesKey(key)]
|
||||
}.first()
|
||||
}
|
||||
|
||||
override suspend fun remove(key: String) {
|
||||
context.authDataStore.edit { prefs ->
|
||||
prefs.remove(stringPreferencesKey(key))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then use it in your InsForge client
|
||||
install(Auth) {
|
||||
browserLauncher = ...
|
||||
persistSession = true
|
||||
sessionStorage = DataStoreSessionStorage(context)
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
<CodeGroup>
|
||||
```bash npm
|
||||
npm install @insforge/sdk@latest
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn add @insforge/sdk@latest
|
||||
```
|
||||
|
||||
```bash pnpm
|
||||
pnpm add @insforge/sdk@latest
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
```javascript
|
||||
import { createClient } from '@insforge/sdk';
|
||||
|
||||
const insforge = createClient({
|
||||
baseUrl: 'https://your-app.insforge.app',
|
||||
anonKey: 'your-anon-key' // Optional: for public/unauthenticated requests
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
export const ServiceIcons = ({ services }) => {
|
||||
const iconMap = {
|
||||
database: { src: '/images/icons/database.svg', title: 'Database' },
|
||||
auth: { src: '/images/icons/auth.svg', title: 'Authentication' },
|
||||
storage: { src: '/images/icons/storage.svg', title: 'Storage' },
|
||||
ai: { src: '/images/icons/ai.svg', title: 'AI Services' },
|
||||
functions: { src: '/images/icons/function.svg', title: 'Edge Functions' }
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex gap-2 mt-3" style={{pointerEvents: 'none'}}>
|
||||
{services.map((service) => {
|
||||
const icon = iconMap[service.toLowerCase()];
|
||||
return icon ? (
|
||||
<img
|
||||
key={service}
|
||||
src={icon.src}
|
||||
alt={icon.title}
|
||||
title={icon.title}
|
||||
className="w-5 h-5 opacity-70"
|
||||
style={{pointerEvents: 'none'}}
|
||||
/>
|
||||
) : null;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
Add InsForge to your Swift Package Manager dependencies:
|
||||
|
||||
```swift
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/insforge/insforge-swift.git", from: "0.0.9")
|
||||
]
|
||||
```
|
||||
|
||||
```swift
|
||||
import InsForge
|
||||
|
||||
let insforge = InsForgeClient(
|
||||
baseURL: URL(string: "https://your-app.insforge.app")!,
|
||||
anonKey: "your-anon-key"
|
||||
)
|
||||
```
|
||||
|
||||
### Enable Logging (Optional)
|
||||
|
||||
For debugging, you can configure the SDK log level and destination:
|
||||
|
||||
```swift
|
||||
let options = InsForgeClientOptions(
|
||||
global: .init(
|
||||
logLevel: .debug,
|
||||
logDestination: .osLog,
|
||||
logSubsystem: "com.example.MyApp"
|
||||
)
|
||||
)
|
||||
|
||||
let insforge = InsForgeClient(
|
||||
baseURL: URL(string: "https://your-app.insforge.app")!,
|
||||
anonKey: "your-anon-key",
|
||||
options: options
|
||||
)
|
||||
```
|
||||
|
||||
**Log Levels:**
|
||||
|
||||
| Level | Description |
|
||||
|-------|-------------|
|
||||
| `.trace` | Most verbose, includes all internal details |
|
||||
| `.debug` | Detailed information for debugging |
|
||||
| `.info` | General operational information (default) |
|
||||
| `.warning` | Warnings that don't prevent operation |
|
||||
| `.error` | Errors that affect functionality |
|
||||
| `.critical` | Critical failures |
|
||||
|
||||
**Log Destinations:**
|
||||
|
||||
| Destination | Description |
|
||||
|-------------|-------------|
|
||||
| `.console` | Standard output (print) |
|
||||
| `.osLog` | Apple's unified logging system (recommended for iOS/macOS) |
|
||||
| `.none` | Disable logging |
|
||||
| `.custom` | Provide your own LogHandler factory |
|
||||
|
||||
<Note>
|
||||
Use `.info` or `.error` in production to avoid exposing sensitive data in logs.
|
||||
</Note>
|
||||
Reference in New Issue
Block a user