insforge 1.3.0 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/auth/package.json +5 -3
- package/auth/src/lib/broadcastService.ts +115 -117
- package/auth/src/lib/insforge.ts +8 -0
- package/auth/src/main.tsx +2 -4
- package/auth/src/pages/SignInPage.tsx +60 -60
- package/auth/src/pages/SignUpPage.tsx +60 -60
- package/auth/src/pages/VerifyEmailPage.tsx +18 -0
- package/auth/tsconfig.json +2 -1
- package/backend/package.json +10 -6
- package/backend/src/api/middlewares/rate-limiters.ts +127 -127
- package/backend/src/api/routes/ai/index.routes.ts +475 -468
- package/backend/src/api/routes/auth/index.routes.ts +85 -32
- package/backend/src/api/routes/auth/oauth.routes.ts +11 -6
- package/backend/src/api/routes/database/index.routes.ts +2 -0
- package/backend/src/api/routes/database/records.routes.ts +39 -175
- package/backend/src/api/routes/database/rpc.routes.ts +69 -0
- package/backend/src/api/routes/deployments/index.routes.ts +192 -0
- package/backend/src/api/routes/docs/index.routes.ts +3 -2
- package/backend/src/api/routes/email/index.routes.ts +35 -35
- package/backend/src/api/routes/functions/index.routes.ts +3 -3
- package/backend/src/api/routes/metadata/index.routes.ts +26 -0
- package/backend/src/api/routes/webhooks/index.routes.ts +109 -0
- package/backend/src/infra/database/database.manager.ts +0 -10
- package/backend/src/infra/database/migrations/018_schema-rework.sql +441 -0
- package/backend/src/infra/database/migrations/019_create-deployments-table.sql +36 -0
- package/backend/src/infra/database/migrations/020_add-audio-modality.sql +11 -0
- package/backend/src/infra/database/migrations/bootstrap/bootstrap-migrations.js +103 -0
- package/backend/src/infra/security/token.manager.ts +1 -4
- package/backend/src/providers/ai/openrouter.provider.ts +12 -3
- package/backend/src/providers/database/base.provider.ts +39 -0
- package/backend/src/providers/database/cloud.provider.ts +159 -0
- package/backend/src/providers/deployments/vercel.provider.ts +516 -0
- package/backend/src/server.ts +19 -7
- package/backend/src/services/ai/ai-config.service.ts +6 -6
- package/backend/src/services/ai/ai-model.service.ts +60 -60
- package/backend/src/services/ai/ai-usage.service.ts +7 -7
- package/backend/src/services/ai/chat-completion.service.ts +415 -220
- package/backend/src/services/ai/helpers.ts +64 -64
- package/backend/src/services/ai/index.ts +13 -13
- package/backend/src/services/auth/auth-config.service.ts +4 -4
- package/backend/src/services/auth/auth-otp.service.ts +6 -6
- package/backend/src/services/auth/auth.service.ts +134 -74
- package/backend/src/services/auth/index.ts +4 -4
- package/backend/src/services/auth/oauth-config.service.ts +12 -12
- package/backend/src/services/database/database-advance.service.ts +19 -55
- package/backend/src/services/database/database-table.service.ts +38 -85
- package/backend/src/services/database/postgrest-proxy.service.ts +165 -0
- package/backend/src/services/deployments/deployment.service.ts +693 -0
- package/backend/src/services/functions/function.service.ts +61 -41
- package/backend/src/services/logs/audit.service.ts +10 -10
- package/backend/src/services/secrets/secret.service.ts +101 -27
- package/backend/src/services/storage/storage.service.ts +30 -30
- package/backend/src/services/usage/usage.service.ts +6 -6
- package/backend/src/types/ai.ts +8 -0
- package/backend/src/types/auth.ts +5 -1
- package/backend/src/types/database.ts +2 -0
- package/backend/src/types/deployments.ts +33 -0
- package/backend/src/types/storage.ts +1 -1
- package/backend/src/types/webhooks.ts +45 -0
- package/backend/src/utils/cookies.ts +34 -35
- package/backend/src/utils/environment.ts +0 -14
- package/backend/src/utils/s3-config-loader.ts +64 -64
- package/backend/src/utils/seed.ts +334 -301
- package/backend/src/utils/sql-parser.ts +126 -0
- package/backend/src/utils/utils.ts +114 -114
- package/backend/src/utils/validations.ts +10 -10
- package/backend/tests/local/test-rpc.sh +141 -0
- package/backend/tests/local/test-secrets.sh +1 -1
- package/backend/tests/manual/test-ai-model-plugins.sh +258 -0
- package/backend/tests/manual/test-rawsql-modes.sh +24 -24
- package/backend/tests/unit/database-advance.test.ts +326 -0
- package/backend/tests/unit/helpers.test.ts +2 -2
- package/claude-plugin/skills/insforge-schema-patterns/SKILL.md +13 -10
- package/docker-compose.prod.yml +1 -1
- package/docker-compose.yml +1 -1
- package/docs/agent-docs/deployment.md +79 -0
- package/docs/changelog.mdx +165 -72
- package/docs/core-concepts/ai/architecture.mdx +1 -23
- package/docs/core-concepts/ai/sdk.mdx +26 -1
- package/docs/core-concepts/authentication/architecture.mdx +6 -8
- package/docs/core-concepts/authentication/sdk.mdx +387 -91
- package/docs/core-concepts/authentication/ui-components/customization.mdx +460 -256
- package/docs/core-concepts/authentication/ui-components/nextjs.mdx +50 -24
- package/docs/core-concepts/authentication/ui-components/react-router.mdx +18 -19
- package/docs/core-concepts/authentication/ui-components/react.mdx +26 -19
- package/docs/core-concepts/database/architecture.mdx +58 -21
- package/docs/core-concepts/database/pgvector.mdx +138 -0
- package/docs/core-concepts/database/sdk.mdx +17 -17
- package/docs/core-concepts/deployments/architecture.mdx +152 -0
- package/docs/core-concepts/email/architecture.mdx +4 -2
- package/docs/core-concepts/functions/architecture.mdx +1 -1
- package/docs/core-concepts/functions/sdk.mdx +0 -1
- package/docs/core-concepts/realtime/architecture.mdx +1 -1
- package/docs/core-concepts/storage/architecture.mdx +1 -1
- package/docs/core-concepts/storage/sdk.mdx +25 -25
- package/docs/docs.json +14 -6
- package/docs/favicon.png +0 -0
- package/docs/favicon.svg +3 -18
- package/docs/images/changelog/dec-2025/apple-oauth.mp4 +0 -0
- package/docs/images/changelog/dec-2025/moreModels.png +0 -0
- package/docs/images/changelog/dec-2025/multi-region.webp +0 -0
- package/docs/images/changelog/dec-2025/postgres-connection.webp +0 -0
- package/docs/images/changelog/dec-2025/realtime2.png +0 -0
- package/docs/images/mcp-setup/CC-MCP-1.mp4 +0 -0
- package/docs/images/mcp-setup/CC-MCP-2.mp4 +0 -0
- package/docs/images/mcp-setup/Cursor-MCP-1.mp4 +0 -0
- package/docs/images/mcp-setup/Cursor-MCP-2.mp4 +0 -0
- package/docs/images/mcp-setup/Cursor-MCP-3.mp4 +0 -0
- package/docs/images/mcp-setup/claude-code-connect.png +0 -0
- package/docs/images/mcp-setup/cline-1.png +0 -0
- package/docs/images/mcp-setup/cline-2.png +0 -0
- package/docs/images/mcp-setup/cline-3.png +0 -0
- package/docs/images/mcp-setup/connect-project.png +0 -0
- package/docs/images/mcp-setup/copilot-1.png +0 -0
- package/docs/images/mcp-setup/copilot-2.png +0 -0
- package/docs/images/mcp-setup/copilot-3.png +0 -0
- package/docs/images/mcp-setup/mcp-json-1.png +0 -0
- package/docs/images/mcp-setup/mcp-json-2.png +0 -0
- package/docs/images/mcp-setup/qoder-1.png +0 -0
- package/docs/images/mcp-setup/qoder-2.png +0 -0
- package/docs/images/mcp-setup/roocode-1.png +0 -0
- package/docs/images/mcp-setup/roocode-2.png +0 -0
- package/docs/images/mcp-setup/trae-1.png +0 -0
- package/docs/images/mcp-setup/trae-2.png +0 -0
- package/docs/images/mcp-setup/trae-3.png +0 -0
- package/docs/images/mcp-setup/trae-4.png +0 -0
- package/docs/images/mcp-setup/trae-5.png +0 -0
- package/docs/images/mcp-setup/windsurf-1.png +0 -0
- package/docs/images/mcp-setup/windsurf-2.png +0 -0
- package/docs/insforge-instructions-sdk.md +7 -3
- package/docs/introduction.mdx +9 -8
- package/docs/mcp-setup.mdx +332 -0
- package/docs/oauth-server.mdx +563 -0
- package/docs/partnership.mdx +79 -10
- package/docs/quickstart.mdx +1 -1
- package/docs/vscode-extension.mdx +74 -0
- package/eslint.config.js +1 -0
- package/examples/response-examples.md +1 -1
- package/frontend/package.json +1 -1
- package/frontend/src/App.tsx +8 -3
- package/frontend/src/assets/logos/antigravity.svg +1 -0
- package/frontend/src/assets/logos/copilot.svg +10 -0
- package/frontend/src/assets/logos/deepseek.svg +139 -0
- package/frontend/src/assets/logos/kiro.svg +9 -0
- package/frontend/src/assets/logos/qoder.svg +4 -0
- package/frontend/src/assets/logos/qwen.svg +15 -0
- package/frontend/src/components/CodeBlock.tsx +2 -2
- package/frontend/src/components/ConnectCTA.tsx +3 -2
- package/frontend/src/components/datagrid/DataGrid.tsx +90 -62
- package/frontend/src/components/datagrid/datagridTypes.tsx +2 -1
- package/frontend/src/components/datagrid/index.ts +1 -1
- package/frontend/src/components/index.ts +0 -1
- package/frontend/src/components/layout/AppHeader.tsx +4 -27
- package/frontend/src/components/layout/AppSidebar.tsx +85 -100
- package/frontend/src/components/layout/Layout.tsx +34 -32
- package/frontend/src/components/layout/PrimaryMenu.tsx +12 -4
- package/frontend/src/components/radix/Select.tsx +151 -151
- package/frontend/src/features/ai/components/AIConfigCard.tsx +200 -200
- package/frontend/src/features/ai/components/AIEmptyState.tsx +23 -23
- package/frontend/src/features/ai/components/ModalityFilterSidebar.tsx +102 -101
- package/frontend/src/features/ai/components/ModelSelectionDialog.tsx +135 -135
- package/frontend/src/features/ai/components/ModelSelectionGrid.tsx +51 -51
- package/frontend/src/features/ai/components/SystemPromptDialog.tsx +118 -118
- package/frontend/src/features/ai/components/index.ts +6 -6
- package/frontend/src/features/ai/helpers.ts +147 -141
- package/frontend/src/features/ai/pages/AIPage.tsx +166 -166
- package/frontend/src/features/auth/components/AuthPreview.tsx +96 -96
- package/frontend/src/features/auth/components/UsersDataGrid.tsx +55 -31
- package/frontend/src/features/auth/components/index.ts +5 -5
- package/frontend/src/features/auth/pages/AuthMethodsPage.tsx +275 -275
- package/frontend/src/features/dashboard/pages/DashboardPage.tsx +1 -1
- package/frontend/src/features/database/components/DatabaseDataGrid.tsx +0 -2
- package/frontend/src/features/database/components/ForeignKeyCell.tsx +38 -11
- package/frontend/src/features/database/components/ForeignKeyPopover.tsx +18 -8
- package/frontend/src/features/database/components/LinkRecordModal.tsx +61 -13
- package/frontend/src/features/database/components/RecordFormField.tsx +1 -1
- package/frontend/src/features/database/components/TableSidebar.tsx +0 -3
- package/frontend/src/features/database/components/TablesEmptyState.tsx +1 -1
- package/frontend/src/features/database/components/TemplatePreview.tsx +1 -2
- package/frontend/src/features/database/constants.ts +16 -28
- package/frontend/src/features/database/hooks/useCSVImport.ts +3 -2
- package/frontend/src/features/database/hooks/useRawSQL.ts +3 -2
- package/frontend/src/features/database/hooks/useTables.ts +5 -7
- package/frontend/src/features/database/pages/FunctionsPage.tsx +0 -5
- package/frontend/src/features/database/pages/IndexesPage.tsx +0 -5
- package/frontend/src/features/database/pages/PoliciesPage.tsx +0 -5
- package/frontend/src/features/database/pages/SQLEditorPage.tsx +2 -2
- package/frontend/src/features/database/pages/TriggersPage.tsx +0 -5
- package/frontend/src/features/database/services/advance.service.ts +1 -15
- package/frontend/src/features/database/services/record.service.ts +4 -20
- package/frontend/src/features/database/services/table.service.ts +1 -4
- package/frontend/src/features/database/templates/ai-chatbot.ts +6 -6
- package/frontend/src/features/database/templates/ecommerce-platform.ts +2 -2
- package/frontend/src/features/database/templates/instagram-clone.ts +10 -10
- package/frontend/src/features/database/templates/notion-clone.ts +8 -8
- package/frontend/src/features/database/templates/reddit-clone.ts +10 -10
- package/frontend/src/features/deployments/components/DeploymentRow.tsx +93 -0
- package/frontend/src/features/deployments/components/DeploymentsEmptyState.tsx +15 -0
- package/frontend/src/features/deployments/hooks/useDeployments.ts +157 -0
- package/frontend/src/features/deployments/pages/DeploymentsPage.tsx +318 -0
- package/frontend/src/features/deployments/services/deployments.service.ts +63 -0
- package/frontend/src/features/functions/components/FunctionRow.tsx +72 -72
- package/frontend/src/features/functions/components/FunctionsSidebar.tsx +56 -56
- package/frontend/src/features/functions/components/SecretRow.tsx +3 -3
- package/frontend/src/features/functions/components/index.ts +5 -5
- package/frontend/src/features/functions/hooks/useFunctions.ts +5 -4
- package/frontend/src/features/functions/hooks/useSecrets.ts +6 -9
- package/frontend/src/features/functions/pages/SecretsPage.tsx +118 -118
- package/frontend/src/features/functions/services/function.service.ts +8 -25
- package/frontend/src/features/functions/services/secret.service.ts +23 -41
- package/frontend/src/features/login/pages/CloudLoginPage.tsx +125 -118
- package/frontend/src/features/logs/components/LogDetailPanel.tsx +41 -0
- package/frontend/src/features/logs/components/LogsDataGrid.tsx +32 -1
- package/frontend/src/features/logs/components/index.ts +1 -0
- package/frontend/src/features/logs/pages/LogsPage.tsx +36 -6
- package/frontend/src/features/onboard/components/ApiCredentialsSection.tsx +59 -0
- package/frontend/src/features/onboard/components/ConnectionStringSection.tsx +180 -0
- package/frontend/src/features/onboard/components/McpConnectionSection.tsx +159 -0
- package/frontend/src/features/onboard/components/OnboardingController.tsx +68 -0
- package/frontend/src/features/onboard/components/OnboardingModal.tsx +121 -267
- package/frontend/src/features/onboard/components/ShowPasswordButton.tsx +21 -0
- package/frontend/src/features/onboard/components/index.ts +9 -4
- package/frontend/src/features/onboard/components/mcp/CursorDeeplinkGenerator.tsx +1 -1
- package/frontend/src/features/onboard/components/mcp/QoderDeeplinkGenerator.tsx +36 -0
- package/frontend/src/features/onboard/components/mcp/helpers.tsx +123 -98
- package/frontend/src/features/onboard/components/mcp/index.ts +4 -3
- package/frontend/src/features/onboard/index.ts +17 -13
- package/frontend/src/features/settings/pages/SettingsPage.tsx +349 -0
- package/frontend/src/features/visualizer/components/AuthNode.tsx +4 -4
- package/frontend/src/features/visualizer/components/SchemaVisualizer.tsx +21 -8
- package/frontend/src/features/visualizer/pages/VisualizerPage.tsx +10 -1
- package/frontend/src/index.css +249 -249
- package/frontend/src/lib/contexts/ModalContext.tsx +35 -0
- package/frontend/src/lib/hooks/useMetadata.ts +45 -1
- package/frontend/src/lib/hooks/useModal.tsx +2 -0
- package/frontend/src/lib/routing/AppRoutes.tsx +103 -99
- package/frontend/src/lib/services/metadata.service.ts +20 -3
- package/frontend/src/lib/utils/menuItems.ts +223 -207
- package/frontend/src/lib/utils/utils.ts +196 -196
- package/functions/server.ts +315 -315
- package/functions/worker-template.js +1 -1
- package/openapi/ai.yaml +115 -5
- package/openapi/auth.yaml +97 -17
- package/openapi/logs.yaml +0 -2
- package/openapi/metadata.yaml +0 -2
- package/openapi/records.yaml +21 -21
- package/openapi/tables.yaml +1 -2
- package/package.json +1 -1
- package/shared-schemas/package.json +1 -1
- package/shared-schemas/src/ai-api.schema.ts +251 -143
- package/shared-schemas/src/ai.schema.ts +63 -63
- package/shared-schemas/src/auth-api.schema.ts +34 -6
- package/shared-schemas/src/auth.schema.ts +17 -10
- package/shared-schemas/src/cloud-events.schema.ts +26 -0
- package/shared-schemas/src/deployments-api.schema.ts +55 -0
- package/shared-schemas/src/deployments.schema.ts +30 -0
- package/shared-schemas/src/docs.schema.ts +8 -2
- package/shared-schemas/src/email-api.schema.ts +30 -30
- package/shared-schemas/src/functions-api.schema.ts +13 -4
- package/shared-schemas/src/functions.schema.ts +1 -1
- package/shared-schemas/src/index.ts +22 -18
- package/shared-schemas/src/metadata.schema.ts +30 -4
- package/shared-schemas/src/secrets-api.schema.ts +44 -0
- package/shared-schemas/src/secrets.schema.ts +15 -0
- package/zeabur/README.md +13 -0
- package/zeabur/template.yml +20 -51
- package/backend/src/types/profile.ts +0 -55
- package/frontend/src/components/ProjectInfoModal.tsx +0 -128
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: OAuth Server
|
|
3
|
+
description: Use InsForge as an OAuth 2.0 identity provider to authenticate users in third-party applications
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
InsForge can function as an OAuth 2.0 identity provider, allowing third-party applications to authenticate users with "Sign in with InsForge". This enables developers building on your platform to leverage InsForge's authentication system without managing their own user credentials.
|
|
9
|
+
|
|
10
|
+
## Use Cases
|
|
11
|
+
|
|
12
|
+
<CardGroup cols={2}>
|
|
13
|
+
<Card title="Developer Platforms" icon="code">
|
|
14
|
+
Enable third-party developers to build integrations with "Sign in with InsForge" while you maintain control over user data access.
|
|
15
|
+
</Card>
|
|
16
|
+
|
|
17
|
+
<Card title="AI Agents & MCP" icon="robot">
|
|
18
|
+
Authenticate AI agents and LLM tools via Model Context Protocol with OAuth-based authorization.
|
|
19
|
+
</Card>
|
|
20
|
+
|
|
21
|
+
<Card title="Partner Applications" icon="handshake">
|
|
22
|
+
Allow partner applications to authenticate users against your InsForge project without sharing credentials.
|
|
23
|
+
</Card>
|
|
24
|
+
|
|
25
|
+
<Card title="CLI & Desktop Apps" icon="terminal">
|
|
26
|
+
Issue OAuth tokens to command-line tools and desktop applications that need API access.
|
|
27
|
+
</Card>
|
|
28
|
+
</CardGroup>
|
|
29
|
+
|
|
30
|
+
## OAuth 2.0 Flow
|
|
31
|
+
|
|
32
|
+
InsForge implements the **Authorization Code flow with PKCE** (Proof Key for Code Exchange), the most secure OAuth flow for both web and native applications.
|
|
33
|
+
|
|
34
|
+
```mermaid
|
|
35
|
+
sequenceDiagram
|
|
36
|
+
participant App as Your Application
|
|
37
|
+
participant User as User Browser
|
|
38
|
+
participant InsForge as InsForge Auth
|
|
39
|
+
participant API as InsForge API
|
|
40
|
+
|
|
41
|
+
App->>App: Generate code_verifier & code_challenge
|
|
42
|
+
App->>User: Redirect to /api/oauth/v1/authorize
|
|
43
|
+
User->>InsForge: User authenticates
|
|
44
|
+
InsForge->>User: Authorization prompt
|
|
45
|
+
User->>InsForge: User approves
|
|
46
|
+
InsForge->>App: Redirect with authorization code
|
|
47
|
+
App->>InsForge: POST /api/oauth/v1/token<br/>(code + code_verifier)
|
|
48
|
+
InsForge->>InsForge: Verify PKCE
|
|
49
|
+
InsForge->>App: Access token + Refresh token
|
|
50
|
+
App->>API: API requests with access token
|
|
51
|
+
API->>App: Protected resources
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Getting Started
|
|
55
|
+
|
|
56
|
+
<Steps>
|
|
57
|
+
<Step title="Register Your Application">
|
|
58
|
+
Contact InsForge to register your application as an OAuth client. You'll receive:
|
|
59
|
+
- **Client ID**: Public identifier for your application
|
|
60
|
+
- **Client Secret**: Confidential key for server-side token exchange
|
|
61
|
+
- **Allowed Redirect URIs**: URLs where users can be redirected after authorization
|
|
62
|
+
</Step>
|
|
63
|
+
|
|
64
|
+
<Step title="Configure Scopes">
|
|
65
|
+
Define which permissions your application needs:
|
|
66
|
+
|
|
67
|
+
| Scope | Description |
|
|
68
|
+
|-------|-------------|
|
|
69
|
+
| `user:read` | Read user profile information |
|
|
70
|
+
| `organizations:read` | List user's organizations |
|
|
71
|
+
| `projects:read` | Read project metadata |
|
|
72
|
+
| `projects:write` | Create and modify projects |
|
|
73
|
+
</Step>
|
|
74
|
+
|
|
75
|
+
<Step title="Implement Authorization Flow">
|
|
76
|
+
Integrate the OAuth flow into your application using the endpoints below.
|
|
77
|
+
</Step>
|
|
78
|
+
</Steps>
|
|
79
|
+
|
|
80
|
+
## Endpoints
|
|
81
|
+
|
|
82
|
+
### Authorization Endpoint
|
|
83
|
+
|
|
84
|
+
Redirect users to this endpoint to initiate the OAuth flow.
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
GET https://api.insforge.dev/api/oauth/v1/authorize
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Query Parameters:**
|
|
91
|
+
|
|
92
|
+
| Parameter | Required | Description |
|
|
93
|
+
|-----------|----------|-------------|
|
|
94
|
+
| `client_id` | Yes | Your application's client ID |
|
|
95
|
+
| `redirect_uri` | Yes | URL to redirect after authorization (must be pre-registered) |
|
|
96
|
+
| `response_type` | Yes | Must be `code` |
|
|
97
|
+
| `scope` | Yes | Space-separated list of scopes |
|
|
98
|
+
| `state` | Yes | Random string for CSRF protection |
|
|
99
|
+
| `code_challenge` | Yes | PKCE code challenge (base64url-encoded SHA256 hash) |
|
|
100
|
+
| `code_challenge_method` | Yes | Must be `S256` |
|
|
101
|
+
|
|
102
|
+
**Example:**
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
https://api.insforge.dev/api/oauth/v1/authorize?
|
|
106
|
+
client_id=clf_abc123xyz&
|
|
107
|
+
redirect_uri=https://example.com/callback&
|
|
108
|
+
response_type=code&
|
|
109
|
+
scope=user:read%20organizations:read&
|
|
110
|
+
state=random_state_string&
|
|
111
|
+
code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&
|
|
112
|
+
code_challenge_method=S256
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Token Endpoint
|
|
116
|
+
|
|
117
|
+
Exchange the authorization code for access and refresh tokens.
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
POST https://api.insforge.dev/api/oauth/v1/token
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Request Body (JSON):**
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"grant_type": "authorization_code",
|
|
128
|
+
"code": "AUTH_CODE_FROM_CALLBACK",
|
|
129
|
+
"redirect_uri": "https://example.com/callback",
|
|
130
|
+
"client_id": "clf_abc123xyz",
|
|
131
|
+
"client_secret": "your_client_secret",
|
|
132
|
+
"code_verifier": "your_original_code_verifier"
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Response:**
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"access_token": "eyJhbGciOiJIUzI1NiIs...",
|
|
141
|
+
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
|
|
142
|
+
"token_type": "Bearer",
|
|
143
|
+
"expires_in": 3600
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Refresh Token
|
|
148
|
+
|
|
149
|
+
Exchange a refresh token for a new access token.
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
POST https://api.insforge.dev/api/oauth/v1/token
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Request Body (JSON):**
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"grant_type": "refresh_token",
|
|
160
|
+
"refresh_token": "your_refresh_token",
|
|
161
|
+
"client_id": "clf_abc123xyz",
|
|
162
|
+
"client_secret": "your_client_secret"
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### User Profile Endpoint
|
|
167
|
+
|
|
168
|
+
Retrieve the authenticated user's profile information.
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
GET https://api.insforge.dev/auth/v1/profile
|
|
172
|
+
Authorization: Bearer {access_token}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Response:**
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
{
|
|
179
|
+
"user": {
|
|
180
|
+
"id": "uuid-string",
|
|
181
|
+
"email": "user@example.com",
|
|
182
|
+
"profile": {
|
|
183
|
+
"name": "John Doe",
|
|
184
|
+
"avatar_url": "https://..."
|
|
185
|
+
},
|
|
186
|
+
"email_verified": true,
|
|
187
|
+
"created_at": "2025-01-01T00:00:00Z"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Implementation Guide
|
|
193
|
+
|
|
194
|
+
### Generate PKCE Parameters
|
|
195
|
+
|
|
196
|
+
PKCE adds an extra layer of security by ensuring the application that started the flow is the same one completing it.
|
|
197
|
+
|
|
198
|
+
<Tabs>
|
|
199
|
+
<Tab title="Node.js">
|
|
200
|
+
```javascript
|
|
201
|
+
const crypto = require('crypto');
|
|
202
|
+
|
|
203
|
+
// Generate a random code verifier (keep this secret, stored server-side)
|
|
204
|
+
function generateCodeVerifier() {
|
|
205
|
+
return crypto.randomBytes(32).toString('base64url');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Generate the code challenge from the verifier
|
|
209
|
+
function generateCodeChallenge(verifier) {
|
|
210
|
+
return crypto
|
|
211
|
+
.createHash('sha256')
|
|
212
|
+
.update(verifier)
|
|
213
|
+
.digest('base64url');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Usage
|
|
217
|
+
const codeVerifier = generateCodeVerifier();
|
|
218
|
+
const codeChallenge = generateCodeChallenge(codeVerifier);
|
|
219
|
+
|
|
220
|
+
// Store codeVerifier in session, send codeChallenge to authorization endpoint
|
|
221
|
+
```
|
|
222
|
+
</Tab>
|
|
223
|
+
<Tab title="Python">
|
|
224
|
+
```python
|
|
225
|
+
import secrets
|
|
226
|
+
import hashlib
|
|
227
|
+
import base64
|
|
228
|
+
|
|
229
|
+
def generate_code_verifier():
|
|
230
|
+
return secrets.token_urlsafe(32)
|
|
231
|
+
|
|
232
|
+
def generate_code_challenge(verifier):
|
|
233
|
+
digest = hashlib.sha256(verifier.encode()).digest()
|
|
234
|
+
return base64.urlsafe_b64encode(digest).rstrip(b'=').decode()
|
|
235
|
+
|
|
236
|
+
# Usage
|
|
237
|
+
code_verifier = generate_code_verifier()
|
|
238
|
+
code_challenge = generate_code_challenge(code_verifier)
|
|
239
|
+
|
|
240
|
+
# Store code_verifier in session, send code_challenge to authorization endpoint
|
|
241
|
+
```
|
|
242
|
+
</Tab>
|
|
243
|
+
<Tab title="Browser (Web Crypto)">
|
|
244
|
+
```javascript
|
|
245
|
+
async function generateCodeVerifier() {
|
|
246
|
+
const array = new Uint8Array(32);
|
|
247
|
+
crypto.getRandomValues(array);
|
|
248
|
+
return base64UrlEncode(array);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function generateCodeChallenge(verifier) {
|
|
252
|
+
const encoder = new TextEncoder();
|
|
253
|
+
const data = encoder.encode(verifier);
|
|
254
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
255
|
+
return base64UrlEncode(new Uint8Array(digest));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function base64UrlEncode(buffer) {
|
|
259
|
+
return btoa(String.fromCharCode(...buffer))
|
|
260
|
+
.replace(/\+/g, '-')
|
|
261
|
+
.replace(/\//g, '_')
|
|
262
|
+
.replace(/=+$/, '');
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
</Tab>
|
|
266
|
+
</Tabs>
|
|
267
|
+
|
|
268
|
+
### Complete Server-Side Example
|
|
269
|
+
|
|
270
|
+
Here's a complete Express.js implementation. First, create a `.env` file with your credentials:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# .env - DO NOT commit this file to version control
|
|
274
|
+
SESSION_SECRET=your-secure-random-secret-min-32-chars
|
|
275
|
+
INSFORGE_CLIENT_ID=clf_your_client_id
|
|
276
|
+
INSFORGE_CLIENT_SECRET=your_client_secret
|
|
277
|
+
INSFORGE_URL=https://api.insforge.dev
|
|
278
|
+
REDIRECT_URI=http://localhost:3000/auth/callback
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
<Note>
|
|
282
|
+
Generate a secure session secret using: `node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"`
|
|
283
|
+
</Note>
|
|
284
|
+
|
|
285
|
+
Then implement the OAuth flow:
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
require('dotenv').config();
|
|
289
|
+
const express = require('express');
|
|
290
|
+
const crypto = require('crypto');
|
|
291
|
+
const session = require('express-session');
|
|
292
|
+
|
|
293
|
+
const app = express();
|
|
294
|
+
|
|
295
|
+
// Validate required environment variables
|
|
296
|
+
const requiredEnvVars = ['SESSION_SECRET', 'INSFORGE_CLIENT_ID', 'INSFORGE_CLIENT_SECRET'];
|
|
297
|
+
for (const envVar of requiredEnvVars) {
|
|
298
|
+
if (!process.env[envVar]) {
|
|
299
|
+
console.error(`Missing required environment variable: ${envVar}`);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
app.use(express.json());
|
|
305
|
+
app.use(session({
|
|
306
|
+
secret: process.env.SESSION_SECRET,
|
|
307
|
+
resave: false,
|
|
308
|
+
saveUninitialized: true,
|
|
309
|
+
cookie: { secure: process.env.NODE_ENV === 'production' }
|
|
310
|
+
}));
|
|
311
|
+
|
|
312
|
+
const config = {
|
|
313
|
+
clientId: process.env.INSFORGE_CLIENT_ID,
|
|
314
|
+
clientSecret: process.env.INSFORGE_CLIENT_SECRET,
|
|
315
|
+
insforgeUrl: process.env.INSFORGE_URL || 'https://api.insforge.dev',
|
|
316
|
+
redirectUri: process.env.REDIRECT_URI || 'http://localhost:3000/auth/callback',
|
|
317
|
+
scopes: 'user:read organizations:read'
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// Step 1: Initiate OAuth flow
|
|
321
|
+
app.get('/auth/login', (req, res) => {
|
|
322
|
+
// Generate PKCE parameters
|
|
323
|
+
const codeVerifier = crypto.randomBytes(32).toString('base64url');
|
|
324
|
+
const codeChallenge = crypto
|
|
325
|
+
.createHash('sha256')
|
|
326
|
+
.update(codeVerifier)
|
|
327
|
+
.digest('base64url');
|
|
328
|
+
|
|
329
|
+
// Generate state for CSRF protection
|
|
330
|
+
const state = crypto.randomBytes(16).toString('hex');
|
|
331
|
+
|
|
332
|
+
// Store in session
|
|
333
|
+
req.session.codeVerifier = codeVerifier;
|
|
334
|
+
req.session.oauthState = state;
|
|
335
|
+
|
|
336
|
+
// Build authorization URL
|
|
337
|
+
const authUrl = new URL(`${config.insforgeUrl}/api/oauth/v1/authorize`);
|
|
338
|
+
authUrl.searchParams.set('client_id', config.clientId);
|
|
339
|
+
authUrl.searchParams.set('redirect_uri', config.redirectUri);
|
|
340
|
+
authUrl.searchParams.set('response_type', 'code');
|
|
341
|
+
authUrl.searchParams.set('scope', config.scopes);
|
|
342
|
+
authUrl.searchParams.set('state', state);
|
|
343
|
+
authUrl.searchParams.set('code_challenge', codeChallenge);
|
|
344
|
+
authUrl.searchParams.set('code_challenge_method', 'S256');
|
|
345
|
+
|
|
346
|
+
res.redirect(authUrl.toString());
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Step 2: Handle callback
|
|
350
|
+
app.get('/auth/callback', async (req, res) => {
|
|
351
|
+
const { code, state, error } = req.query;
|
|
352
|
+
|
|
353
|
+
// Check for errors
|
|
354
|
+
if (error) {
|
|
355
|
+
return res.status(400).send(`OAuth error: ${error}`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Validate state to prevent CSRF
|
|
359
|
+
if (state !== req.session.oauthState) {
|
|
360
|
+
return res.status(403).send('Invalid state parameter');
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
// Exchange code for tokens
|
|
365
|
+
const tokenResponse = await fetch(`${config.insforgeUrl}/api/oauth/v1/token`, {
|
|
366
|
+
method: 'POST',
|
|
367
|
+
headers: { 'Content-Type': 'application/json' },
|
|
368
|
+
body: JSON.stringify({
|
|
369
|
+
grant_type: 'authorization_code',
|
|
370
|
+
code,
|
|
371
|
+
redirect_uri: config.redirectUri,
|
|
372
|
+
client_id: config.clientId,
|
|
373
|
+
client_secret: config.clientSecret,
|
|
374
|
+
code_verifier: req.session.codeVerifier
|
|
375
|
+
})
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
const tokens = await tokenResponse.json();
|
|
379
|
+
|
|
380
|
+
if (!tokenResponse.ok) {
|
|
381
|
+
throw new Error(tokens.error || 'Token exchange failed');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Fetch user profile
|
|
385
|
+
const profileResponse = await fetch(`${config.insforgeUrl}/auth/v1/profile`, {
|
|
386
|
+
headers: { 'Authorization': `Bearer ${tokens.access_token}` }
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const { user } = await profileResponse.json();
|
|
390
|
+
|
|
391
|
+
// Store tokens and user in session
|
|
392
|
+
req.session.accessToken = tokens.access_token;
|
|
393
|
+
req.session.refreshToken = tokens.refresh_token;
|
|
394
|
+
req.session.user = user;
|
|
395
|
+
|
|
396
|
+
// Clean up PKCE data
|
|
397
|
+
delete req.session.codeVerifier;
|
|
398
|
+
delete req.session.oauthState;
|
|
399
|
+
|
|
400
|
+
res.redirect('/dashboard');
|
|
401
|
+
} catch (err) {
|
|
402
|
+
console.error('OAuth callback error:', err);
|
|
403
|
+
res.status(500).send('Authentication failed');
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// Step 3: Use access token for API calls
|
|
408
|
+
app.get('/api/organizations', async (req, res) => {
|
|
409
|
+
if (!req.session.accessToken) {
|
|
410
|
+
return res.status(401).json({ error: 'Not authenticated' });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const response = await fetch(`${config.insforgeUrl}/organizations/v1`, {
|
|
414
|
+
headers: { 'Authorization': `Bearer ${req.session.accessToken}` }
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const data = await response.json();
|
|
418
|
+
res.json(data);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
app.listen(3000, () => console.log('Server running on http://localhost:3000'));
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### Popup Mode for SPAs
|
|
425
|
+
|
|
426
|
+
For single-page applications, you can open the OAuth flow in a popup window:
|
|
427
|
+
|
|
428
|
+
```javascript
|
|
429
|
+
function loginWithPopup() {
|
|
430
|
+
const width = 500;
|
|
431
|
+
const height = 600;
|
|
432
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
433
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
434
|
+
|
|
435
|
+
const popup = window.open(
|
|
436
|
+
'/auth/login?mode=popup',
|
|
437
|
+
'insforge-oauth',
|
|
438
|
+
`width=${width},height=${height},left=${left},top=${top}`
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
// Listen for completion message from popup
|
|
442
|
+
window.addEventListener('message', (event) => {
|
|
443
|
+
if (event.origin !== window.location.origin) return;
|
|
444
|
+
|
|
445
|
+
if (event.data.type === 'oauth-complete') {
|
|
446
|
+
popup.close();
|
|
447
|
+
// Handle successful authentication
|
|
448
|
+
window.location.reload();
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
In your callback handler, post a message to the parent window:
|
|
455
|
+
|
|
456
|
+
```javascript
|
|
457
|
+
// In callback route, after successful token exchange
|
|
458
|
+
if (req.query.mode === 'popup') {
|
|
459
|
+
res.send(`
|
|
460
|
+
<script>
|
|
461
|
+
window.opener.postMessage({ type: 'oauth-complete' }, window.location.origin);
|
|
462
|
+
window.close();
|
|
463
|
+
</script>
|
|
464
|
+
`);
|
|
465
|
+
}
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
## Security Considerations
|
|
469
|
+
|
|
470
|
+
<CardGroup cols={2}>
|
|
471
|
+
<Card title="Always Use PKCE" icon="shield-check">
|
|
472
|
+
PKCE is mandatory for all OAuth flows. It prevents authorization code interception attacks.
|
|
473
|
+
</Card>
|
|
474
|
+
|
|
475
|
+
<Card title="Validate State" icon="fingerprint">
|
|
476
|
+
Always verify the state parameter in callbacks to prevent CSRF attacks.
|
|
477
|
+
</Card>
|
|
478
|
+
|
|
479
|
+
<Card title="Secure Token Storage" icon="lock">
|
|
480
|
+
Store access tokens in memory or secure httpOnly cookies. Never expose tokens in URLs or localStorage.
|
|
481
|
+
</Card>
|
|
482
|
+
|
|
483
|
+
<Card title="Use HTTPS" icon="globe">
|
|
484
|
+
All OAuth endpoints require HTTPS in production. Never transmit tokens over unencrypted connections.
|
|
485
|
+
</Card>
|
|
486
|
+
|
|
487
|
+
<Card title="Short Token Expiry" icon="clock">
|
|
488
|
+
Access tokens expire in 1 hour. Use refresh tokens to obtain new access tokens without re-authentication.
|
|
489
|
+
</Card>
|
|
490
|
+
|
|
491
|
+
<Card title="Scope Minimization" icon="minimize">
|
|
492
|
+
Request only the scopes your application needs. Users are more likely to approve limited permissions.
|
|
493
|
+
</Card>
|
|
494
|
+
</CardGroup>
|
|
495
|
+
|
|
496
|
+
## Token Claims
|
|
497
|
+
|
|
498
|
+
Access tokens are JWTs containing the following claims:
|
|
499
|
+
|
|
500
|
+
| Claim | Description |
|
|
501
|
+
|-------|-------------|
|
|
502
|
+
| `sub` | User ID (UUID) |
|
|
503
|
+
| `email` | User's email address |
|
|
504
|
+
| `role` | User role (`authenticated`) |
|
|
505
|
+
| `client_id` | OAuth client ID that requested the token |
|
|
506
|
+
| `scope` | Granted scopes |
|
|
507
|
+
| `iat` | Issued at timestamp |
|
|
508
|
+
| `exp` | Expiration timestamp |
|
|
509
|
+
| `iss` | Issuer (`insforge`) |
|
|
510
|
+
| `aud` | Audience (`insforge-api`) |
|
|
511
|
+
|
|
512
|
+
## Error Handling
|
|
513
|
+
|
|
514
|
+
### Authorization Errors
|
|
515
|
+
|
|
516
|
+
If authorization fails, users are redirected to your `redirect_uri` with error parameters:
|
|
517
|
+
|
|
518
|
+
```
|
|
519
|
+
https://example.com/callback?error=access_denied&error_description=User%20denied%20access
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
Common error codes:
|
|
523
|
+
|
|
524
|
+
| Error | Description |
|
|
525
|
+
|-------|-------------|
|
|
526
|
+
| `invalid_request` | Missing or invalid parameters |
|
|
527
|
+
| `unauthorized_client` | Client not authorized for this grant type |
|
|
528
|
+
| `access_denied` | User denied the authorization request |
|
|
529
|
+
| `invalid_scope` | Requested scope is invalid or unknown |
|
|
530
|
+
|
|
531
|
+
### Token Errors
|
|
532
|
+
|
|
533
|
+
Token endpoint errors return JSON:
|
|
534
|
+
|
|
535
|
+
```json
|
|
536
|
+
{
|
|
537
|
+
"error": "invalid_grant",
|
|
538
|
+
"error_description": "Authorization code has expired"
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
| Error | Description |
|
|
543
|
+
|-------|-------------|
|
|
544
|
+
| `invalid_grant` | Code expired, already used, or verifier mismatch |
|
|
545
|
+
| `invalid_client` | Client authentication failed |
|
|
546
|
+
| `invalid_request` | Missing required parameters |
|
|
547
|
+
|
|
548
|
+
## Rate Limits
|
|
549
|
+
|
|
550
|
+
OAuth endpoints are rate-limited to prevent abuse:
|
|
551
|
+
|
|
552
|
+
| Endpoint | Limit |
|
|
553
|
+
|----------|-------|
|
|
554
|
+
| `/authorize` | 100 requests per minute per IP |
|
|
555
|
+
| `/token` | 50 requests per minute per client |
|
|
556
|
+
| `/profile` | 100 requests per minute per token |
|
|
557
|
+
|
|
558
|
+
## Resources
|
|
559
|
+
|
|
560
|
+
<Card title="OAuth Example Repository" icon="github" href="https://github.com/InsForge/insforge-oauth-example">
|
|
561
|
+
Complete working example showing how to integrate "Sign in with InsForge" into your application.
|
|
562
|
+
</Card>
|
|
563
|
+
|
package/docs/partnership.mdx
CHANGED
|
@@ -88,6 +88,7 @@ Partner platforms can:
|
|
|
88
88
|
- ✅ Delete projects
|
|
89
89
|
- ✅ Get project's authorization token for access
|
|
90
90
|
- ✅ Get project's usage
|
|
91
|
+
- ✅ Get aggregated usage across all partnership projects (for billing)
|
|
91
92
|
|
|
92
93
|
## API Reference
|
|
93
94
|
|
|
@@ -371,6 +372,60 @@ Partner platforms can:
|
|
|
371
372
|
}
|
|
372
373
|
```
|
|
373
374
|
|
|
375
|
+
### Get Partnership Total Usage
|
|
376
|
+
Retrieve aggregated usage metrics across all projects under your partnership for a date range. This endpoint is designed for billing and reporting purposes, providing a consolidated view of resource consumption.
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
GET /partnership/v1/:partnerId/usage?start_date=2025-11-01&end_date=2025-11-30
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Query Parameters:**
|
|
383
|
+
- `start_date` (optional): Start date in YYYY-MM-DD format (defaults to 7 days ago)
|
|
384
|
+
- `end_date` (optional): End date in YYYY-MM-DD format (defaults to today)
|
|
385
|
+
|
|
386
|
+
**Response:**
|
|
387
|
+
```json
|
|
388
|
+
{
|
|
389
|
+
"partnership": {
|
|
390
|
+
"id": "ps_abc123xyz",
|
|
391
|
+
"name": "Partner Name"
|
|
392
|
+
},
|
|
393
|
+
"period": {
|
|
394
|
+
"start": "2025-11-01T00:00:00Z",
|
|
395
|
+
"end": "2025-11-30T23:59:59Z"
|
|
396
|
+
},
|
|
397
|
+
"summary": {
|
|
398
|
+
"database_bytes": 10485760,
|
|
399
|
+
"storage_bytes": 52428800,
|
|
400
|
+
"ai_tokens": 150000,
|
|
401
|
+
"mcp_calls": 1200,
|
|
402
|
+
"egress_bytes": 20971520,
|
|
403
|
+
"ai_credits": 15.5,
|
|
404
|
+
"email_requests": 500,
|
|
405
|
+
"function_calls": 3000,
|
|
406
|
+
"ec2_compute": 36000
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
**Usage Metric Types:**
|
|
412
|
+
|
|
413
|
+
| Metric | Type | Description |
|
|
414
|
+
|--------|------|-------------|
|
|
415
|
+
| `database_bytes` | Peak | Peak total database footprint (sum per day, max across days) |
|
|
416
|
+
| `storage_bytes` | Peak | Peak total storage footprint (sum per day, max across days) |
|
|
417
|
+
| `ai_tokens` | Cumulative | Total AI tokens consumed |
|
|
418
|
+
| `mcp_calls` | Cumulative | Total MCP/tool calls made |
|
|
419
|
+
| `egress_bytes` | Cumulative | Total data transfer (origin + CDN) |
|
|
420
|
+
| `ai_credits` | Cumulative | Total AI credits consumed |
|
|
421
|
+
| `email_requests` | Cumulative | Total emails sent |
|
|
422
|
+
| `function_calls` | Cumulative | Total serverless function invocations |
|
|
423
|
+
| `ec2_compute` | Cumulative | Total compute seconds used |
|
|
424
|
+
|
|
425
|
+
<Note>
|
|
426
|
+
This endpoint includes usage from deleted projects within the specified date range, ensuring complete billing accuracy.
|
|
427
|
+
</Note>
|
|
428
|
+
|
|
374
429
|
</Tab>
|
|
375
430
|
</Tabs>
|
|
376
431
|
|
|
@@ -461,16 +516,8 @@ const createProject = async (userId: string, projectName: string) => {
|
|
|
461
516
|
};
|
|
462
517
|
|
|
463
518
|
// 3. Use project credentials
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const insForgeClient = new InsForgeClient({
|
|
467
|
-
baseUrl: project.access_host,
|
|
468
|
-
apiKey: project.api_key
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
// Now you can use all InsForge features
|
|
472
|
-
await insForgeClient.database.query('SELECT * FROM users');
|
|
473
|
-
};
|
|
519
|
+
console.log(project.access_host);
|
|
520
|
+
console.log(project.api_key);
|
|
474
521
|
```
|
|
475
522
|
|
|
476
523
|
### White-Label Integration Flow
|
|
@@ -597,6 +644,28 @@ const deleteProject = async (projectId: string) => {
|
|
|
597
644
|
throw new Error(`Failed to delete project: ${response.status}`);
|
|
598
645
|
}
|
|
599
646
|
};
|
|
647
|
+
|
|
648
|
+
// 4. Get partnership total usage (for billing)
|
|
649
|
+
const getPartnershipUsage = async (startDate: string, endDate: string) => {
|
|
650
|
+
const params = new URLSearchParams({ start_date: startDate, end_date: endDate });
|
|
651
|
+
const response = await fetch(
|
|
652
|
+
`https://api.insforge.dev/partnership/v1/${PARTNER_ID}/usage?${params}`,
|
|
653
|
+
{
|
|
654
|
+
method: 'GET',
|
|
655
|
+
headers: {
|
|
656
|
+
'X-Partnership-Secret': `${SECRET_KEY}`
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
|
|
661
|
+
const data = await response.json();
|
|
662
|
+
console.log(`Period: ${data.period.start} to ${data.period.end}`);
|
|
663
|
+
console.log(`Database: ${data.summary.database_bytes} bytes (peak)`);
|
|
664
|
+
console.log(`Storage: ${data.summary.storage_bytes} bytes (peak)`);
|
|
665
|
+
console.log(`AI Credits: ${data.summary.ai_credits}`);
|
|
666
|
+
console.log(`Egress: ${data.summary.egress_bytes} bytes`);
|
|
667
|
+
return data;
|
|
668
|
+
};
|
|
600
669
|
```
|
|
601
670
|
|
|
602
671
|
## Parameter and Response Reference
|