@obul.ai/sdk 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +79 -0
  2. package/package.json +15 -6
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @obul.ai/sdk
2
+
3
+ Single-package Obul BFF SDK facade with browser client, server core, and framework adapters.
4
+
5
+ ## What is a BFF?
6
+ BFF stands for **Backend For Frontend**. It's a small server that sits between your browser app and Obul's APIs. The browser only talks to your BFF, and the BFF handles OAuth, token storage, session cookies, and proxying API calls. This keeps secrets and tokens off the client and lets you enforce auth, rate limits, and request policies in one place.
7
+
8
+ ## Install
9
+ ```bash
10
+ npm install @obul.ai/sdk
11
+ ```
12
+
13
+ ## Exports
14
+ - `@obul.ai/sdk/browser` (browser client)
15
+ - `@obul.ai/sdk/server` (server core)
16
+ - `@obul.ai/sdk/adapters/express`
17
+ - `@obul.ai/sdk/adapters/next`
18
+ - `@obul.ai/sdk/adapters/hono`
19
+ - `@obul.ai/sdk/adapters/cloudflare`
20
+
21
+ ## Example integrations
22
+
23
+ ### Express (BFF server)
24
+ ```js
25
+ import express from "express"
26
+ import { createObulExpressRouter } from "@obul.ai/sdk/adapters/express"
27
+
28
+ const app = express()
29
+ const router = createObulExpressRouter({
30
+ issuerUrl: process.env.OBUL_ISSUER_URL,
31
+ authEndpoint: process.env.OBUL_AUTH_ENDPOINT,
32
+ tokenEndpoint: process.env.OBUL_TOKEN_ENDPOINT,
33
+ revocationEndpoint: process.env.OBUL_REVOCATION_ENDPOINT,
34
+ apiBaseUrl: process.env.OBUL_API_BASE_URL,
35
+ clientId: process.env.OBUL_CLIENT_ID,
36
+ clientSecret: process.env.OBUL_CLIENT_SECRET,
37
+ redirectUri: process.env.OBUL_REDIRECT_URI,
38
+ scopes: (process.env.OBUL_SCOPES ?? "openid profile email").split(" ")
39
+ })
40
+
41
+ app.use(router)
42
+ app.listen(3000)
43
+ ```
44
+
45
+ ### React / Vite (browser client)
46
+ ```ts
47
+ import { createObulClient } from "@obul.ai/sdk/browser"
48
+
49
+ const obul = createObulClient({
50
+ baseUrl: "", // BFF origin, if different from the browser origin
51
+ postLoginRedirect: window.location.href,
52
+ postLogoutRedirect: "/",
53
+ sessionCheckIntervalMs: 10_000
54
+ })
55
+
56
+ // Example: trigger login
57
+ obul.signIn()
58
+ ```
59
+
60
+ ### Next.js (App Router, client component)
61
+ ```tsx
62
+ "use client"
63
+
64
+ import { useEffect, useMemo } from "react"
65
+ import { createObulClient } from "@obul.ai/sdk/browser"
66
+
67
+ export function ObulLoginButton() {
68
+ const obul = useMemo(() => createObulClient({ baseUrl: "" }), [])
69
+
70
+ useEffect(() => {
71
+ obul.getSession().catch(() => {})
72
+ }, [obul])
73
+
74
+ return <button onClick={() => obul.signIn()}>Sign in</button>
75
+ }
76
+ ```
77
+
78
+ ## Repo
79
+ See the repo for the Express example and additional docs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obul.ai/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Single-package Obul BFF SDK facade with browser client, server core, and framework adapters.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,7 +40,8 @@
40
40
  }
41
41
  },
42
42
  "files": [
43
- "dist"
43
+ "dist",
44
+ "README.md"
44
45
  ],
45
46
  "sideEffects": false,
46
47
  "scripts": {
@@ -54,10 +55,18 @@
54
55
  "next": ">=13.0.0"
55
56
  },
56
57
  "peerDependenciesMeta": {
57
- "cookie-parser": { "optional": true },
58
- "express": { "optional": true },
59
- "hono": { "optional": true },
60
- "next": { "optional": true }
58
+ "cookie-parser": {
59
+ "optional": true
60
+ },
61
+ "express": {
62
+ "optional": true
63
+ },
64
+ "hono": {
65
+ "optional": true
66
+ },
67
+ "next": {
68
+ "optional": true
69
+ }
61
70
  },
62
71
  "devDependencies": {
63
72
  "@types/cookie-parser": "^1.4.7",