insforge by insforge/agent-skills
npx skills add https://github.com/insforge/agent-skills --skill insforge此技能涵盖使用 @insforge/sdk 进行客户端 SDK 集成。对于后端基础设施操作(创建表、检查模式、部署函数、管理密钥、管理存储桶、网站部署、定时任务和调度、日志等),请使用 insforge-cli 技能。
npm install @insforge/sdk@latest
import { createClient } from '@insforge/sdk'
const insforge = createClient({
baseUrl: 'https://your-project.region.insforge.app',
anonKey: 'your-anon-key'
})
| 模块 | SDK 集成 |
|---|---|
| 数据库 | database/sdk-integration.md |
| 认证 | auth/sdk-integration.md |
| 存储 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 函数 | functions/sdk-integration.md |
| AI | ai/sdk-integration.md |
| 实时 | realtime/sdk-integration.md |
| 模块 | 内容 |
|---|---|
| 数据库 | CRUD 操作、过滤器、分页、RPC 调用 |
| 认证 | 注册/登录、OAuth、会话、个人资料、密码重置 |
| 存储 | 上传、下载、删除文件 |
| 函数 | 调用边缘函数 |
| AI | 聊天补全、图像生成、嵌入 |
| 实时 | 连接、订阅、发布事件 |
| 指南 | 使用时机 |
|---|---|
| database/postgres-rls.md | 编写或审查 RLS 策略时 —— 涵盖无限递归预防、SECURITY DEFINER 模式、性能提示和常见的 InsForge RLS 模式 |
对于实时频道和数据库触发器,请使用 insforge db query 配合 SQL 来创建向频道发布消息的触发器。实时 SDK 用于前端事件处理和消息传递,而非后端配置。
当数据库记录更改时自动发布事件。
-- 创建触发器函数
CREATE OR REPLACE FUNCTION notify_order_changes()
RETURNS TRIGGER AS $$
BEGIN
PERFORM realtime.publish(
'order:' || NEW.id::text, -- 频道
TG_OP || '_order', -- 事件: INSERT_order, UPDATE_order
jsonb_build_object(
'id', NEW.id,
'status', NEW.status,
'total', NEW.total
)
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
-- 附加到表
CREATE TRIGGER order_realtime
AFTER INSERT OR UPDATE ON orders
FOR EACH ROW
EXECUTE FUNCTION notify_order_changes();
CREATE OR REPLACE FUNCTION notify_order_status()
RETURNS TRIGGER AS $$
BEGIN
PERFORM realtime.publish(
'order:' || NEW.id::text,
'status_changed',
jsonb_build_object('id', NEW.id, 'status', NEW.status)
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
CREATE TRIGGER order_status_trigger
AFTER UPDATE ON orders
FOR EACH ROW
WHEN (OLD.status IS DISTINCT FROM NEW.status)
EXECUTE FUNCTION notify_order_status();
RLS 默认禁用。要限制频道访问:
启用 RLS
ALTER TABLE realtime.channels ENABLE ROW LEVEL SECURITY; ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY;
限制订阅(对 channels 表的 SELECT 操作)
CREATE POLICY "users_subscribe_own_orders" ON realtime.channels FOR SELECT TO authenticated USING ( pattern = 'order:%' AND EXISTS ( SELECT 1 FROM orders WHERE id = NULLIF(split_part(realtime.channel_name(), ':', 2), '')::uuid AND user_id = auth.uid() ) );
限制发布(对 messages 表的 INSERT 操作)
CREATE POLICY "members_publish_chat" ON realtime.messages FOR INSERT TO authenticated WITH CHECK ( channel_name LIKE 'chat:%' AND EXISTS ( SELECT 1 FROM chat_members WHERE room_id = NULLIF(split_part(channel_name, ':', 2), '')::uuid AND user_id = auth.uid() ) );
快速参考
| 任务 | SQL |
|---|---|
| 创建频道 | INSERT INTO realtime.channels (pattern, description, enabled) VALUES (...) |
| 创建触发器 | CREATE TRIGGER ... EXECUTE FUNCTION ... |
| 从 SQL 发布 | PERFORM realtime.publish(channel, event, payload) |
| 启用 RLS | ALTER TABLE realtime.channels ENABLE ROW LEVEL SECURITY |
先创建频道模式,然后再从前端订阅
realtime.channels 表enabled 设置为 true使用特定的频道模式
% 模式(例如,order:% 对应 order:123)notifications)| 错误 | 解决方案 |
|---|---|
| 订阅未定义的频道模式 | 先在 realtime.channels 中创建频道模式 |
| 频道未收到消息 | 确保频道 enabled 为 true |
| 没有触发器就发布 | 创建数据库触发器以在变更时自动发布 |
1. 创建频道模式 → INSERT INTO realtime.channels
2. 确保 enabled = true → 将 enabled 设置为 true
3. 根据需要创建触发器 → 在数据库变更时自动发布
4. 继续使用 SDK 订阅 → 使用与模式匹配的频道名称
这些模块仍需要 HTTP API 调用,因为 CLI 尚未支持它们:
所有 SDK 方法都返回 { data, error }。
| 模块 | 方法 |
|---|---|
insforge.database | .from().select(), .insert(), .update(), .delete(), .rpc() |
insforge.auth | .signUp(), .signInWithPassword(), .signInWithOAuth(), .signOut(), .getCurrentSession() |
insforge.storage | .from().upload(), .uploadAuto(), .download(), .remove() |
insforge.functions | .invoke() |
insforge.ai | .chat.completions.create(), .images.generate(), .embeddings.create() |
insforge.realtime | .connect(), .subscribe(), .publish(), .on(), .disconnect() |
insert([{...}]) 而不是 insert({...})createClient({ isServerMode: true }),将令牌保存在 httpOnly cookie 中,并在服务器上执行认证流程。参见 auth/sdk-integration.mdurl 和 key 都保存到数据库,以便进行下载/删除操作/functions/{slug}(不带 /api 前缀)@insforge/react、@insforge/nextjs 和 @insforge/react-router 已弃用。请勿安装或使用它们。直接使用 @insforge/sdk 来获取包括认证在内的所有功能。vercel.json 文件以支持 SPA 路由(React、React Router 应用)。download-template 工具会自动包含此文件。每周安装量
2.4K
代码仓库
GitHub 星标
12
首次出现
2026年1月26日
安全审计
安装于
gemini-cli2.3K
github-copilot2.3K
codex2.3K
cursor2.3K
cline2.3K
antigravity2.3K
This skill covers client-side SDK integration using @insforge/sdk. For backend infrastructure operations (creating tables, inspecting schema, deploying functions, secrets, managing storage buckets, website deployments, cron job and schedules, logs, etc.), use the insforge-cli skill.
npm install @insforge/sdk@latest
import { createClient } from '@insforge/sdk'
const insforge = createClient({
baseUrl: 'https://your-project.region.insforge.app',
anonKey: 'your-anon-key'
})
| Module | SDK Integration |
|---|---|
| Database | database/sdk-integration.md |
| Auth | auth/sdk-integration.md |
| Storage | storage/sdk-integration.md |
| Functions | functions/sdk-integration.md |
| AI | ai/sdk-integration.md |
| Real-time | realtime/sdk-integration.md |
| Module | Content |
|---|---|
| Database | CRUD operations, filters, pagination, RPC calls |
| Auth | Sign up/in, OAuth, sessions, profiles, password reset |
| Storage | Upload, download, delete files |
| Functions | Invoke edge functions |
| AI | Chat completions, image generation, embeddings |
| Real-time | Connect, subscribe, publish events |
| Guide | When to Use |
|---|---|
| database/postgres-rls.md | Writing or reviewing RLS policies — covers infinite recursion prevention, SECURITY DEFINER patterns, performance tips, and common InsForge RLS patterns |
For real-time channels and database triggers, use insforge db query with SQL to create triggers that publish to channels. The real-time SDK is for frontend event handling and messaging, not backend configuration.
Automatically publish events when database records change.
-- Create trigger function
CREATE OR REPLACE FUNCTION notify_order_changes()
RETURNS TRIGGER AS $$
BEGIN
PERFORM realtime.publish(
'order:' || NEW.id::text, -- channel
TG_OP || '_order', -- event: INSERT_order, UPDATE_order
jsonb_build_object(
'id', NEW.id,
'status', NEW.status,
'total', NEW.total
)
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
-- Attach to table
CREATE TRIGGER order_realtime
AFTER INSERT OR UPDATE ON orders
FOR EACH ROW
EXECUTE FUNCTION notify_order_changes();
CREATE OR REPLACE FUNCTION notify_order_status()
RETURNS TRIGGER AS $$
BEGIN
PERFORM realtime.publish(
'order:' || NEW.id::text,
'status_changed',
jsonb_build_object('id', NEW.id, 'status', NEW.status)
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
CREATE TRIGGER order_status_trigger
AFTER UPDATE ON orders
FOR EACH ROW
WHEN (OLD.status IS DISTINCT FROM NEW.status)
EXECUTE FUNCTION notify_order_status();
RLS is disabled by default. To restrict channel access:
Enable RLS
ALTER TABLE realtime.channels ENABLE ROW LEVEL SECURITY; ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY;
Restrict Subscribe (SELECT on channels)
CREATE POLICY "users_subscribe_own_orders" ON realtime.channels FOR SELECT TO authenticated USING ( pattern = 'order:%' AND EXISTS ( SELECT 1 FROM orders WHERE id = NULLIF(split_part(realtime.channel_name(), ':', 2), '')::uuid AND user_id = auth.uid() ) );
Restrict Publish (INSERT on messages)
CREATE POLICY "members_publish_chat" ON realtime.messages FOR INSERT TO authenticated WITH CHECK ( channel_name LIKE 'chat:%' AND EXISTS ( SELECT 1 FROM chat_members WHERE room_id = NULLIF(split_part(channel_name, ':', 2), '')::uuid AND user_id = auth.uid() ) );
Quick Reference
| Task | SQL |
|---|---|
| Create channel | INSERT INTO realtime.channels (pattern, description, enabled) VALUES (...) |
| Create trigger | CREATE TRIGGER ... EXECUTE FUNCTION ... |
| Publish from SQL | PERFORM realtime.publish(channel, event, payload) |
| Enable RLS | ALTER TABLE realtime.channels ENABLE ROW LEVEL SECURITY |
Create channel patterns first before subscribing from frontend
realtime.channels tableenabled is set to trueUse specific channel patterns
% patterns for dynamic channels (e.g., order:% for order:123)notifications)| Mistake | Solution |
|---|---|
| Subscribing to undefined channel pattern | Create channel pattern in realtime.channels first |
| Channel not receiving messages | Ensure channel enabled is true |
| Publishing without trigger | Create database trigger to auto-publish on changes |
1. Create channel patterns → INSERT INTO realtime.channels
2. Ensure enabled = true → Set enabled to true
3. Create triggers if needed → Auto-publish on database changes
4. Proceed with SDK subscribe → Use channel name matching pattern
These modules still require HTTP API calls because the CLI does not yet support them:
| Module | Backend Configuration |
|---|---|
| Auth | auth/backend-configuration.md |
| AI | ai/backend-configuration.md |
All SDK methods return { data, error }.
| Module | Methods |
|---|---|
insforge.database | .from().select(), .insert(), .update(), .delete(), .rpc() |
insforge.auth | .signUp(), .signInWithPassword(), , , |
insert([{...}]) not insert({...})createClient({ isServerMode: true }), keep tokens in httpOnly cookies, and perform auth flows on the server. See auth/sdk-integration.mdurl AND key to database for download/delete operations/functions/{slug} (without /api prefix)Weekly Installs
2.4K
Repository
GitHub Stars
12
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
gemini-cli2.3K
github-copilot2.3K
codex2.3K
cursor2.3K
cline2.3K
antigravity2.3K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
.signInWithOAuth().signOut().getCurrentSession()insforge.storage | .from().upload(), .uploadAuto(), .download(), .remove() |
insforge.functions | .invoke() |
insforge.ai | .chat.completions.create(), .images.generate(), .embeddings.create() |
insforge.realtime | .connect(), .subscribe(), .publish(), .on(), .disconnect() |
@insforge/react, @insforge/nextjs, and @insforge/react-router are deprecated. Do NOT install or use them. Use @insforge/sdk directly for all features including authentication.vercel.json in the project root for SPA routing (React, React Router apps). The download-template tool includes this automatically.