@dotbots-boutique/auth-sdk 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DotBots.Boutique
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,299 @@
1
+ # @dotbots-boutique/auth-sdk
2
+
3
+ The official authentication and authorisation SDK for apps running on the [DotBots Boutique](https://dotbots.boutique) platform.
4
+
5
+ ## What is DotBots Boutique?
6
+
7
+ [DotBots Boutique](https://dotbots.boutique) is a marketplace platform where vibe coders build and publish apps. The platform handles user management, authentication, authorisation, payments, and infrastructure, and offers a growing set of additional services — so you can focus on building your app.
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @dotbots-boutique/auth-sdk
15
+ ```
16
+
17
+ > **Note:** This package is for **browser use only**. Do not install it in a Deno or Node backend. A separate `@dotbots-boutique/server-sdk` for backend use is coming soon.
18
+
19
+ ---
20
+
21
+ ## Quick start
22
+
23
+ ### React
24
+
25
+ ```tsx
26
+ // main.tsx
27
+ import { DotBotsAuth } from '@dotbots-boutique/auth-sdk';
28
+ import { DotBotsAuthProvider } from '@dotbots-boutique/auth-sdk/react';
29
+
30
+ const auth = new DotBotsAuth({
31
+ appId: import.meta.env.VITE_DOTBOTS_APP_ID,
32
+ apiUrl: import.meta.env.VITE_DOTBOTS_API_URL
33
+ });
34
+
35
+ ReactDOM.createRoot(document.getElementById('root')!).render(
36
+ <DotBotsAuthProvider auth={auth}>
37
+ <App />
38
+ </DotBotsAuthProvider>
39
+ );
40
+ ```
41
+
42
+ ```tsx
43
+ // In any component
44
+ import { useDotBotsAuth } from '@dotbots-boutique/auth-sdk/react';
45
+
46
+ const MyComponent = () => {
47
+ const { user, can, hasRole, fetch, logout } = useDotBotsAuth();
48
+
49
+ return (
50
+ <div>
51
+ <p>Welcome, {user?.name}</p>
52
+ {can('customers.read') && <CustomerList />}
53
+ {hasRole('admin') && <AdminPanel />}
54
+ <button onClick={logout}>Log out</button>
55
+ </div>
56
+ );
57
+ };
58
+ ```
59
+
60
+ ### Without React
61
+
62
+ ```typescript
63
+ import { DotBotsAuth } from '@dotbots-boutique/auth-sdk';
64
+
65
+ const auth = new DotBotsAuth({
66
+ appId: import.meta.env.VITE_DOTBOTS_APP_ID,
67
+ apiUrl: import.meta.env.VITE_DOTBOTS_API_URL
68
+ });
69
+
70
+ await auth.initialize();
71
+
72
+ const user = await auth.getUser();
73
+ console.log(user.name, user.roles);
74
+ ```
75
+
76
+ ---
77
+
78
+ ## How authentication works
79
+
80
+ Your app can run in two modes — the SDK handles both automatically.
81
+
82
+ **Inside an iframe** (embedded in the DotBots Boutique marketplace):
83
+ 1. The SDK sends a `DOTBOTS_READY` message to the marketplace
84
+ 2. The marketplace responds with a short-lived auth code
85
+ 3. The SDK exchanges the code for an access token and refresh token
86
+
87
+ **Standalone** (opened directly on your app's domain):
88
+ 1. The SDK checks for a `?code=` parameter in the URL
89
+ 2. If absent, it redirects the user to the DotBots login page
90
+ 3. After login, the user is redirected back with a code that the SDK exchanges for tokens
91
+
92
+ All tokens are stored in memory only — never in `localStorage`, `sessionStorage`, or cookies.
93
+
94
+ ---
95
+
96
+ ## Making API calls
97
+
98
+ Always use `auth.fetch()` instead of the native `fetch()`. The SDK automatically:
99
+ - Adds the `Authorization`, `X-App-Id` and `X-Environment` headers
100
+ - Routes calls through the local proxy when available
101
+ - Refreshes the access token when it is about to expire
102
+ - Retries once on a `401` response
103
+
104
+ ```typescript
105
+ // GET
106
+ const response = await auth.fetch('/api/customers');
107
+ const customers = await response.json();
108
+
109
+ // POST
110
+ const response = await auth.fetch('/api/customers', {
111
+ method: 'POST',
112
+ body: JSON.stringify({ name: 'Acme' })
113
+ });
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Checking permissions
119
+
120
+ ```typescript
121
+ auth.can('customers.read') // true/false
122
+ auth.canAll(['customers.read', 'customers.write']) // true/false — all required
123
+ auth.canAny(['customers.read', 'invoices.read']) // true/false — at least one
124
+ auth.hasRole('admin') // true/false
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Events
130
+
131
+ ```typescript
132
+ auth.on('tokenRefreshed', () => { });
133
+ auth.on('sessionExpired', () => {
134
+ // Show a message to the user
135
+ });
136
+ auth.on('loggedOut', () => { });
137
+ auth.on('userLoaded', (user) => { });
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Error handling
143
+
144
+ ```typescript
145
+ import { DotBotsAuthError } from '@dotbots-boutique/auth-sdk';
146
+
147
+ try {
148
+ await auth.initialize();
149
+ } catch (error) {
150
+ if (error instanceof DotBotsAuthError) {
151
+ switch (error.code) {
152
+ case 'IFRAME_TIMEOUT':
153
+ // Marketplace did not respond in time
154
+ break;
155
+ case 'UNAUTHORIZED':
156
+ // User has no access to this app
157
+ break;
158
+ case 'NETWORK_ERROR':
159
+ // API unreachable
160
+ break;
161
+ case 'CODE_EXPIRED':
162
+ // Auth code was already expired or invalid
163
+ break;
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Error codes
170
+
171
+ | Code | Description | Fatal |
172
+ |------|-------------|-------|
173
+ | `IFRAME_TIMEOUT` | Marketplace did not respond within the timeout | Yes |
174
+ | `CODE_EXPIRED` | Auth code was already expired or invalid | Yes |
175
+ | `UNAUTHORIZED` | User has no access to this app | Yes |
176
+ | `REFRESH_FAILED` | Token refresh failed | Yes |
177
+ | `NETWORK_ERROR` | API unreachable | Yes |
178
+ | `NOT_INITIALIZED` | `initialize()` has not been called yet | Yes |
179
+ | `PROXY_UNAVAILABLE` | Proxy config could not be fetched | No — falls back to direct API |
180
+
181
+ ---
182
+
183
+ ## Configuration
184
+
185
+ ```typescript
186
+ interface DotBotsConfig {
187
+ appId: string; // Required — app ID assigned by the platform
188
+ apiUrl: string; // Required — always 'https://api.dotbots.ai'
189
+ marketplaceOrigin?: string; // Default: 'https://dotbots.boutique'
190
+ tokenRefreshBuffer?: number; // Default: 60000 (ms before expiry to refresh)
191
+ iframeTimeout?: number; // Default: 5000 (ms to wait for auth code)
192
+ onTokenRefreshFailed?: () => void; // Called when token refresh fails
193
+ }
194
+ ```
195
+
196
+ ---
197
+
198
+ ## DotBotsUser
199
+
200
+ ```typescript
201
+ interface DotBotsUser {
202
+ id: string;
203
+ name: string | null; // null if 'profile' scope not granted
204
+ email: string | null; // null if 'email' scope not granted
205
+ orgId: string;
206
+ orgName: string | null; // null if 'org' scope not granted
207
+ roles: string[];
208
+ permissions: string[];
209
+ avatarUrl: string | null; // null if 'avatar' scope not granted
210
+ }
211
+ ```
212
+
213
+ Fields marked as `null` are not provided by the platform because the user has not granted the corresponding scope. Scopes are declared in your app's `dotbots.boutique.json` file.
214
+
215
+ ---
216
+
217
+ ## Backend integration
218
+
219
+ If your app has a backend, forward the three headers from the frontend request to your backend, and from your backend to the proxy.
220
+
221
+ ```typescript
222
+ // Deno backend example
223
+ app.get('/api/customers', async (req) => {
224
+ const proxyUrl = Deno.env.get('DOTBOTS_PROXY_URL');
225
+
226
+ const response = await fetch(`${proxyUrl}/api/customers`, {
227
+ headers: {
228
+ 'Authorization': req.headers.get('authorization') ?? '',
229
+ 'X-App-Id': req.headers.get('x-app-id') ?? '',
230
+ 'X-Environment': req.headers.get('x-environment') ?? '',
231
+ }
232
+ });
233
+
234
+ return response;
235
+ });
236
+ ```
237
+
238
+ **Never** store tokens in a database or log file, and never forward them to services outside the DotBots platform. The access token is scoped to your specific app — it cannot be used to access any other app's data.
239
+
240
+ ---
241
+
242
+ ## dotbots.boutique.json
243
+
244
+ Your repository must contain a `dotbots.boutique.json` file. Use the `env` field to declare any environment variables your app needs beyond the platform defaults. The platform will ask the installer to fill these in before deployment.
245
+
246
+ ```json
247
+ {
248
+ "dotbotsPromptVersion": "2.1.0",
249
+ "database": true,
250
+ "scopes": {
251
+ "profile": { "description": "Read the user's name", "access": "required" },
252
+ "email": { "description": "Read the user's email", "access": "optional" }
253
+ },
254
+ "roles": [
255
+ { "name": "admin", "description": "Full access" }
256
+ ],
257
+ "permissions": [
258
+ { "name": "customers.read", "description": "View customers" }
259
+ ],
260
+ "env": [
261
+ {
262
+ "name": "STRIPE_API_KEY",
263
+ "description": "Stripe API key for payment processing",
264
+ "required": true,
265
+ "secret": true
266
+ }
267
+ ]
268
+ }
269
+ ```
270
+
271
+ Platform variables (`DATABASE_URL`, `PORT`, `DOTBOTS_APP_ID`, `DOTBOTS_PROXY_URL`, `DOTBOTS_API_URL`) are injected automatically and do not need to be declared here.
272
+
273
+ ---
274
+
275
+ ## Security
276
+
277
+ - Tokens are stored in memory only — never persisted
278
+ - `postMessage` origin is always validated — only messages from `marketplaceOrigin` are accepted
279
+ - Auth codes are single-use and removed from the URL immediately after exchange
280
+ - No runtime dependencies — eliminates supply chain risk entirely
281
+ - Open source — [view the source on GitHub](https://github.com/dotbots-boutique/auth-sdk)
282
+
283
+ To report a security vulnerability, please email [security@dotbots.ai](mailto:security@dotbots.ai) instead of opening a public issue.
284
+
285
+ ---
286
+
287
+ ## Exports
288
+
289
+ ```typescript
290
+ import { DotBotsAuth, DotBotsAuthError } from '@dotbots-boutique/auth-sdk';
291
+ import type { DotBotsUser, DotBotsConfig, DotBotsAuthEvent, DotBotsProxyConfig } from '@dotbots-boutique/auth-sdk';
292
+ import { DotBotsAuthProvider, useDotBotsAuth } from '@dotbots-boutique/auth-sdk/react';
293
+ ```
294
+
295
+ ---
296
+
297
+ ## License
298
+
299
+ [MIT](./LICENSE) — © DotBots Boutique
package/SECURITY.md ADDED
@@ -0,0 +1,51 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.x.x | :white_check_mark: |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ We take security seriously. If you discover a security vulnerability in `@dotbots-boutique/auth-sdk`, please report it responsibly.
12
+
13
+ ### How to Report
14
+
15
+ 1. **Do NOT** open a public GitHub issue for security vulnerabilities
16
+ 2. Email your findings to **security@dotbots.ai**
17
+ 3. Include a detailed description of the vulnerability
18
+ 4. Include steps to reproduce the issue
19
+ 5. If possible, include a suggested fix
20
+
21
+ ### What to Expect
22
+
23
+ - **Acknowledgment**: We will acknowledge your report within 48 hours
24
+ - **Assessment**: We will assess the impact and severity within 5 business days
25
+ - **Resolution**: We aim to release a fix within 14 days for critical issues
26
+ - **Credit**: With your permission, we will credit you in the release notes
27
+
28
+ ### Scope
29
+
30
+ The following are in scope for this security policy:
31
+
32
+ - Token handling and storage
33
+ - postMessage origin validation
34
+ - Authentication flow vulnerabilities
35
+ - Data exposure through the SDK
36
+
37
+ ### Out of Scope
38
+
39
+ - Vulnerabilities in the DotBots API itself (report to security@dotbots.ai separately)
40
+ - Issues in third-party dependencies
41
+ - Issues requiring physical access to a device
42
+
43
+ ## Security Design Principles
44
+
45
+ This SDK follows these security principles:
46
+
47
+ 1. **Tokens are never persisted** — stored only in memory, never in localStorage, sessionStorage, or cookies
48
+ 2. **postMessage origins are always validated** — only messages from the configured marketplace origin are accepted
49
+ 3. **Auth codes are single-use** — removed from URL and memory immediately after exchange
50
+ 4. **No sensitive data in logs** — tokens are never logged, even in development mode
51
+ 5. **Zero runtime dependencies** — minimizes supply chain attack surface