@dcimorra/authhub-sdk 1.1.0 → 1.2.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/README.md +162 -5
- package/dist/index.d.mts +96 -1
- package/dist/index.d.ts +96 -1
- package/dist/index.js +62 -0
- package/dist/index.mjs +62 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# authhub-sdk
|
|
1
|
+
# @dcimorra/authhub-sdk
|
|
2
2
|
|
|
3
|
-
Official TypeScript SDK for [Auth Hub](https://github.com/dcimorra/auth-hub) — self-hosted authentication, database,
|
|
3
|
+
Official TypeScript SDK for [Auth Hub](https://github.com/dcimorra/auth-hub) — self-hosted authentication, database, schema management, storage, OAuth, realtime subscriptions, and cookie-based sessions as a service.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install authhub-sdk
|
|
8
|
+
npm install @dcimorra/authhub-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Or copy the `sdk/` directory into your project and import from it directly.
|
|
@@ -13,7 +13,7 @@ Or copy the `sdk/` directory into your project and import from it directly.
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { AuthHubClient } from "authhub-sdk";
|
|
16
|
+
import { AuthHubClient } from "@dcimorra/authhub-sdk";
|
|
17
17
|
|
|
18
18
|
const hub = new AuthHubClient({
|
|
19
19
|
baseUrl: "https://auth.example.com",
|
|
@@ -79,6 +79,29 @@ const hub = new AuthHubClient({
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
## Session (Cookie-Based SSR Auth)
|
|
83
|
+
|
|
84
|
+
For server-side apps like Next.js where you need cookie-based sessions instead of token-based auth:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// Login — returns the user and Set-Cookie headers to forward to the browser
|
|
88
|
+
const { user, setCookieHeaders } = await hub.session.login(email, password);
|
|
89
|
+
const response = NextResponse.json({ success: true });
|
|
90
|
+
for (const h of setCookieHeaders) response.headers.append("Set-Cookie", h);
|
|
91
|
+
|
|
92
|
+
// Validate a session by forwarding browser cookies
|
|
93
|
+
const cookieHeader = request.headers.get("cookie") || "";
|
|
94
|
+
const user = await hub.session.validate(cookieHeader); // User | null
|
|
95
|
+
|
|
96
|
+
// Logout — returns Set-Cookie headers that clear the session cookies
|
|
97
|
+
const setCookieHeaders = await hub.session.logout(cookieHeader);
|
|
98
|
+
const response = NextResponse.json({ success: true });
|
|
99
|
+
for (const h of setCookieHeaders) response.headers.append("Set-Cookie", h);
|
|
100
|
+
|
|
101
|
+
// Change password via session cookies
|
|
102
|
+
await hub.session.changePassword(cookieHeader, "oldPassword", "newPassword");
|
|
103
|
+
```
|
|
104
|
+
|
|
82
105
|
## Database
|
|
83
106
|
|
|
84
107
|
Full CRUD with advanced query operators.
|
|
@@ -143,6 +166,84 @@ const total = await hub.db.count("products", { active: true });
|
|
|
143
166
|
| `$is` | `IS` | `{ deleted_at: { $is: null } }` |
|
|
144
167
|
| `$not` | `IS NOT` | `{ email: { $not: null } }` |
|
|
145
168
|
|
|
169
|
+
## Schema Management (DDL)
|
|
170
|
+
|
|
171
|
+
Create and modify tables, columns, and constraints remotely via the API. Each project gets its own isolated PostgreSQL database.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// List all tables
|
|
175
|
+
const { tables } = await hub.schema.listTables();
|
|
176
|
+
// => ["articles", "comments"]
|
|
177
|
+
|
|
178
|
+
// Create a table (comes with `id SERIAL PRIMARY KEY` and `created_at TIMESTAMP`)
|
|
179
|
+
await hub.schema.createTable("articles");
|
|
180
|
+
|
|
181
|
+
// Get table details (columns + constraints)
|
|
182
|
+
const info = await hub.schema.getTable("articles");
|
|
183
|
+
console.log(info.columns); // SchemaColumn[]
|
|
184
|
+
console.log(info.constraints); // SchemaConstraint[]
|
|
185
|
+
|
|
186
|
+
// Add columns
|
|
187
|
+
await hub.schema.addColumn("articles", {
|
|
188
|
+
column: "title",
|
|
189
|
+
type: "TEXT",
|
|
190
|
+
nullable: false,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await hub.schema.addColumn("articles", {
|
|
194
|
+
column: "status",
|
|
195
|
+
type: "TEXT",
|
|
196
|
+
nullable: false,
|
|
197
|
+
default: "draft",
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
await hub.schema.addColumn("articles", {
|
|
201
|
+
column: "updated_at",
|
|
202
|
+
type: "TIMESTAMP",
|
|
203
|
+
default: "CURRENT_TIMESTAMP",
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Rename a column
|
|
207
|
+
await hub.schema.renameColumn("articles", {
|
|
208
|
+
column: "title",
|
|
209
|
+
newName: "headline",
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Drop a column (cannot drop system columns: id, created_at, updated_at)
|
|
213
|
+
await hub.schema.dropColumn("articles", "old_field");
|
|
214
|
+
|
|
215
|
+
// Add a unique constraint
|
|
216
|
+
await hub.schema.addConstraint("articles", {
|
|
217
|
+
constraintType: "unique",
|
|
218
|
+
columns: ["slug"],
|
|
219
|
+
name: "uq_articles_slug", // optional, auto-generated if omitted
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Add a foreign key
|
|
223
|
+
await hub.schema.addConstraint("comments", {
|
|
224
|
+
constraintType: "foreign_key",
|
|
225
|
+
columns: ["article_id"],
|
|
226
|
+
referencedTable: "articles",
|
|
227
|
+
referencedColumns: ["id"],
|
|
228
|
+
onDelete: "CASCADE",
|
|
229
|
+
onUpdate: "NO ACTION",
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Drop a constraint
|
|
233
|
+
await hub.schema.dropConstraint("articles", "uq_articles_slug");
|
|
234
|
+
|
|
235
|
+
// Drop a table (CASCADE)
|
|
236
|
+
await hub.schema.dropTable("old_table");
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Supported Column Types
|
|
240
|
+
|
|
241
|
+
`TEXT`, `INTEGER`, `BIGINT`, `SMALLINT`, `REAL`, `DOUBLE PRECISION`, `BOOLEAN`, `DATE`, `TIME`, `TIMESTAMP`, `NUMERIC`, `DECIMAL`, `VARCHAR`, `CHAR`
|
|
242
|
+
|
|
243
|
+
### Supported Foreign Key Actions
|
|
244
|
+
|
|
245
|
+
`NO ACTION`, `RESTRICT`, `CASCADE`, `SET NULL`, `SET DEFAULT`
|
|
246
|
+
|
|
146
247
|
## Storage
|
|
147
248
|
|
|
148
249
|
File upload, download, and bucket management.
|
|
@@ -196,12 +297,68 @@ const buckets = await hub.storage.listBuckets();
|
|
|
196
297
|
await hub.storage.deleteBucket("old-bucket");
|
|
197
298
|
```
|
|
198
299
|
|
|
300
|
+
## OAuth
|
|
301
|
+
|
|
302
|
+
Social login with Google and GitHub.
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
// Get the OAuth URL and redirect the user
|
|
306
|
+
const url = hub.oauth.getAuthUrl("google", "/dashboard");
|
|
307
|
+
window.location.href = url;
|
|
308
|
+
|
|
309
|
+
// Or use the convenience method (browser only)
|
|
310
|
+
hub.oauth.signInWithProvider("github", "/dashboard");
|
|
311
|
+
|
|
312
|
+
// After the redirect, parse tokens from the URL hash
|
|
313
|
+
const result = await hub.oauth.handleCallback();
|
|
314
|
+
if (result) {
|
|
315
|
+
console.log(result.provider); // "google" | "github"
|
|
316
|
+
console.log(result.access_token); // tokens are also stored automatically
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Realtime
|
|
321
|
+
|
|
322
|
+
Subscribe to database mutations via WebSocket.
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// Create a realtime client
|
|
326
|
+
const realtime = hub.realtime("wss://auth.example.com");
|
|
327
|
+
|
|
328
|
+
// Connect and authenticate
|
|
329
|
+
const accessToken = await hub.auth.getAccessToken();
|
|
330
|
+
await realtime.connect(accessToken);
|
|
331
|
+
|
|
332
|
+
// Subscribe to table changes
|
|
333
|
+
realtime.on("table:users", (event, data) => {
|
|
334
|
+
console.log(event); // "INSERT" | "UPDATE" | "DELETE"
|
|
335
|
+
console.log(data); // { table, operation, id, timestamp }
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Subscribe with confirmation
|
|
339
|
+
await realtime.subscribe("table:orders", (event, data) => {
|
|
340
|
+
console.log("Order changed:", event, data);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// Unsubscribe
|
|
344
|
+
realtime.unsubscribe("table:users");
|
|
345
|
+
|
|
346
|
+
// Remove a specific handler
|
|
347
|
+
realtime.off("table:orders", myHandler);
|
|
348
|
+
|
|
349
|
+
// Check connection state
|
|
350
|
+
console.log(realtime.isConnected());
|
|
351
|
+
|
|
352
|
+
// Close when done
|
|
353
|
+
realtime.close();
|
|
354
|
+
```
|
|
355
|
+
|
|
199
356
|
## Error Handling
|
|
200
357
|
|
|
201
358
|
All methods throw `AuthHubError` on failure:
|
|
202
359
|
|
|
203
360
|
```typescript
|
|
204
|
-
import { AuthHubError } from "authhub-sdk";
|
|
361
|
+
import { AuthHubError } from "@dcimorra/authhub-sdk";
|
|
205
362
|
|
|
206
363
|
try {
|
|
207
364
|
await hub.auth.login("user@example.com", "wrong-password");
|
package/dist/index.d.mts
CHANGED
|
@@ -118,6 +118,77 @@ interface DbMutationResult<T = Record<string, unknown>> {
|
|
|
118
118
|
rows: T[];
|
|
119
119
|
[key: string]: unknown;
|
|
120
120
|
}
|
|
121
|
+
/** Valid PostgreSQL column types accepted by the schema API */
|
|
122
|
+
type SchemaColumnType = "TEXT" | "INTEGER" | "BIGINT" | "SMALLINT" | "REAL" | "DOUBLE PRECISION" | "BOOLEAN" | "DATE" | "TIME" | "TIMESTAMP" | "NUMERIC" | "DECIMAL" | "VARCHAR" | "CHAR";
|
|
123
|
+
/** Column descriptor returned by getTable() */
|
|
124
|
+
interface SchemaColumn {
|
|
125
|
+
column_name: string;
|
|
126
|
+
data_type: string;
|
|
127
|
+
is_nullable: string;
|
|
128
|
+
column_default: string | null;
|
|
129
|
+
}
|
|
130
|
+
/** Constraint descriptor returned by getTable() */
|
|
131
|
+
interface SchemaConstraint {
|
|
132
|
+
constraint_name: string;
|
|
133
|
+
constraint_type: string;
|
|
134
|
+
column_name: string;
|
|
135
|
+
foreign_table_name?: string | null;
|
|
136
|
+
foreign_column_name?: string | null;
|
|
137
|
+
}
|
|
138
|
+
/** Response from listTables() */
|
|
139
|
+
interface SchemaListTablesResult {
|
|
140
|
+
tables: string[];
|
|
141
|
+
}
|
|
142
|
+
/** Response from getTable() */
|
|
143
|
+
interface SchemaTableInfo {
|
|
144
|
+
table: string;
|
|
145
|
+
columns: SchemaColumn[];
|
|
146
|
+
constraints: SchemaConstraint[];
|
|
147
|
+
}
|
|
148
|
+
/** Response from createTable() */
|
|
149
|
+
interface SchemaCreateTableResult {
|
|
150
|
+
table: string;
|
|
151
|
+
message: string;
|
|
152
|
+
}
|
|
153
|
+
/** Response from dropTable() */
|
|
154
|
+
interface SchemaDropTableResult {
|
|
155
|
+
table: string;
|
|
156
|
+
message: string;
|
|
157
|
+
}
|
|
158
|
+
/** Options for addColumn() */
|
|
159
|
+
interface SchemaAddColumnOptions {
|
|
160
|
+
column: string;
|
|
161
|
+
type: SchemaColumnType | (string & {});
|
|
162
|
+
nullable?: boolean;
|
|
163
|
+
default?: string | number | boolean;
|
|
164
|
+
}
|
|
165
|
+
/** Options for renameColumn() */
|
|
166
|
+
interface SchemaRenameColumnOptions {
|
|
167
|
+
column: string;
|
|
168
|
+
newName: string;
|
|
169
|
+
}
|
|
170
|
+
/** Foreign key action options */
|
|
171
|
+
type SchemaFkAction = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
172
|
+
/** Options for addConstraint() */
|
|
173
|
+
interface SchemaAddConstraintOptions {
|
|
174
|
+
constraintType: "primary_key" | "unique" | "foreign_key";
|
|
175
|
+
columns: string[];
|
|
176
|
+
name?: string;
|
|
177
|
+
/** Foreign key only */
|
|
178
|
+
referencedTable?: string;
|
|
179
|
+
/** Foreign key only */
|
|
180
|
+
referencedColumns?: string[];
|
|
181
|
+
/** Foreign key only — default: "NO ACTION" */
|
|
182
|
+
onDelete?: SchemaFkAction;
|
|
183
|
+
/** Foreign key only — default: "NO ACTION" */
|
|
184
|
+
onUpdate?: SchemaFkAction;
|
|
185
|
+
}
|
|
186
|
+
/** Generic DDL action response */
|
|
187
|
+
interface SchemaDdlResult {
|
|
188
|
+
table: string;
|
|
189
|
+
message: string;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
}
|
|
121
192
|
interface Bucket {
|
|
122
193
|
id: string;
|
|
123
194
|
name: string;
|
|
@@ -228,6 +299,8 @@ declare class AuthHubClient {
|
|
|
228
299
|
readonly session: SessionModule;
|
|
229
300
|
/** Database CRUD operations */
|
|
230
301
|
readonly db: DbModule;
|
|
302
|
+
/** Database schema / DDL operations (create tables, add columns, etc.) */
|
|
303
|
+
readonly schema: SchemaModule;
|
|
231
304
|
/** File storage operations */
|
|
232
305
|
readonly storage: StorageModule;
|
|
233
306
|
/** OAuth social login helpers */
|
|
@@ -354,6 +427,28 @@ declare class DbModule {
|
|
|
354
427
|
/** Count rows matching a where clause */
|
|
355
428
|
count(table: string, where?: Record<string, unknown>): Promise<number>;
|
|
356
429
|
}
|
|
430
|
+
declare class SchemaModule {
|
|
431
|
+
private client;
|
|
432
|
+
constructor(client: AuthHubClient);
|
|
433
|
+
/** List all tables in the project database */
|
|
434
|
+
listTables(): Promise<SchemaListTablesResult>;
|
|
435
|
+
/** Create a new table (with id SERIAL PRIMARY KEY + created_at TIMESTAMP) */
|
|
436
|
+
createTable(table: string): Promise<SchemaCreateTableResult>;
|
|
437
|
+
/** Get column and constraint info for a table */
|
|
438
|
+
getTable(table: string): Promise<SchemaTableInfo>;
|
|
439
|
+
/** Drop a table (CASCADE) */
|
|
440
|
+
dropTable(table: string): Promise<SchemaDropTableResult>;
|
|
441
|
+
/** Add a column to an existing table */
|
|
442
|
+
addColumn(table: string, options: SchemaAddColumnOptions): Promise<SchemaDdlResult>;
|
|
443
|
+
/** Rename a column */
|
|
444
|
+
renameColumn(table: string, options: SchemaRenameColumnOptions): Promise<SchemaDdlResult>;
|
|
445
|
+
/** Drop a column */
|
|
446
|
+
dropColumn(table: string, column: string): Promise<SchemaDdlResult>;
|
|
447
|
+
/** Add a constraint (primary_key, unique, or foreign_key) */
|
|
448
|
+
addConstraint(table: string, options: SchemaAddConstraintOptions): Promise<SchemaDdlResult>;
|
|
449
|
+
/** Drop a named constraint */
|
|
450
|
+
dropConstraint(table: string, constraint: string): Promise<SchemaDdlResult>;
|
|
451
|
+
}
|
|
357
452
|
declare class StorageModule {
|
|
358
453
|
private client;
|
|
359
454
|
constructor(client: AuthHubClient);
|
|
@@ -455,4 +550,4 @@ declare class AuthHubError extends Error {
|
|
|
455
550
|
constructor(data: AuthHubErrorData);
|
|
456
551
|
}
|
|
457
552
|
|
|
458
|
-
export { AuthHubClient, type AuthHubConfig, AuthHubError, type AuthHubErrorData, type AuthResponse, type Bucket, type CreateBucketOptions, type DbCreateOptions, type DbDeleteOptions, type DbMutationResult, type DbReadOptions, type DbReadResult, type DbUpdateOptions, type ListObjectsOptions, LocalStorageTokenStore, MemoryTokenStore, type MessageResponse, type OAuthHashParams, type OAuthProvider, type OrderBy, RealtimeClient, type RealtimeConfig, type RealtimeMessage, type RealtimeMutationHandler, type RegisterResponse, type SessionLoginResult$1 as SessionLoginResult, type SessionResponse, type StorageListResult, type StorageObject, TokenManager, type TokenPair, type TokenStore, type UploadOptions, type User, type WhereClause, type WhereOperator };
|
|
553
|
+
export { AuthHubClient, type AuthHubConfig, AuthHubError, type AuthHubErrorData, type AuthResponse, type Bucket, type CreateBucketOptions, type DbCreateOptions, type DbDeleteOptions, type DbMutationResult, type DbReadOptions, type DbReadResult, type DbUpdateOptions, type ListObjectsOptions, LocalStorageTokenStore, MemoryTokenStore, type MessageResponse, type OAuthHashParams, type OAuthProvider, type OrderBy, RealtimeClient, type RealtimeConfig, type RealtimeMessage, type RealtimeMutationHandler, type RegisterResponse, type SchemaAddColumnOptions, type SchemaAddConstraintOptions, type SchemaColumn, type SchemaColumnType, type SchemaConstraint, type SchemaCreateTableResult, type SchemaDdlResult, type SchemaDropTableResult, type SchemaFkAction, type SchemaListTablesResult, type SchemaRenameColumnOptions, type SchemaTableInfo, type SessionLoginResult$1 as SessionLoginResult, type SessionResponse, type StorageListResult, type StorageObject, TokenManager, type TokenPair, type TokenStore, type UploadOptions, type User, type WhereClause, type WhereOperator };
|
package/dist/index.d.ts
CHANGED
|
@@ -118,6 +118,77 @@ interface DbMutationResult<T = Record<string, unknown>> {
|
|
|
118
118
|
rows: T[];
|
|
119
119
|
[key: string]: unknown;
|
|
120
120
|
}
|
|
121
|
+
/** Valid PostgreSQL column types accepted by the schema API */
|
|
122
|
+
type SchemaColumnType = "TEXT" | "INTEGER" | "BIGINT" | "SMALLINT" | "REAL" | "DOUBLE PRECISION" | "BOOLEAN" | "DATE" | "TIME" | "TIMESTAMP" | "NUMERIC" | "DECIMAL" | "VARCHAR" | "CHAR";
|
|
123
|
+
/** Column descriptor returned by getTable() */
|
|
124
|
+
interface SchemaColumn {
|
|
125
|
+
column_name: string;
|
|
126
|
+
data_type: string;
|
|
127
|
+
is_nullable: string;
|
|
128
|
+
column_default: string | null;
|
|
129
|
+
}
|
|
130
|
+
/** Constraint descriptor returned by getTable() */
|
|
131
|
+
interface SchemaConstraint {
|
|
132
|
+
constraint_name: string;
|
|
133
|
+
constraint_type: string;
|
|
134
|
+
column_name: string;
|
|
135
|
+
foreign_table_name?: string | null;
|
|
136
|
+
foreign_column_name?: string | null;
|
|
137
|
+
}
|
|
138
|
+
/** Response from listTables() */
|
|
139
|
+
interface SchemaListTablesResult {
|
|
140
|
+
tables: string[];
|
|
141
|
+
}
|
|
142
|
+
/** Response from getTable() */
|
|
143
|
+
interface SchemaTableInfo {
|
|
144
|
+
table: string;
|
|
145
|
+
columns: SchemaColumn[];
|
|
146
|
+
constraints: SchemaConstraint[];
|
|
147
|
+
}
|
|
148
|
+
/** Response from createTable() */
|
|
149
|
+
interface SchemaCreateTableResult {
|
|
150
|
+
table: string;
|
|
151
|
+
message: string;
|
|
152
|
+
}
|
|
153
|
+
/** Response from dropTable() */
|
|
154
|
+
interface SchemaDropTableResult {
|
|
155
|
+
table: string;
|
|
156
|
+
message: string;
|
|
157
|
+
}
|
|
158
|
+
/** Options for addColumn() */
|
|
159
|
+
interface SchemaAddColumnOptions {
|
|
160
|
+
column: string;
|
|
161
|
+
type: SchemaColumnType | (string & {});
|
|
162
|
+
nullable?: boolean;
|
|
163
|
+
default?: string | number | boolean;
|
|
164
|
+
}
|
|
165
|
+
/** Options for renameColumn() */
|
|
166
|
+
interface SchemaRenameColumnOptions {
|
|
167
|
+
column: string;
|
|
168
|
+
newName: string;
|
|
169
|
+
}
|
|
170
|
+
/** Foreign key action options */
|
|
171
|
+
type SchemaFkAction = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
|
|
172
|
+
/** Options for addConstraint() */
|
|
173
|
+
interface SchemaAddConstraintOptions {
|
|
174
|
+
constraintType: "primary_key" | "unique" | "foreign_key";
|
|
175
|
+
columns: string[];
|
|
176
|
+
name?: string;
|
|
177
|
+
/** Foreign key only */
|
|
178
|
+
referencedTable?: string;
|
|
179
|
+
/** Foreign key only */
|
|
180
|
+
referencedColumns?: string[];
|
|
181
|
+
/** Foreign key only — default: "NO ACTION" */
|
|
182
|
+
onDelete?: SchemaFkAction;
|
|
183
|
+
/** Foreign key only — default: "NO ACTION" */
|
|
184
|
+
onUpdate?: SchemaFkAction;
|
|
185
|
+
}
|
|
186
|
+
/** Generic DDL action response */
|
|
187
|
+
interface SchemaDdlResult {
|
|
188
|
+
table: string;
|
|
189
|
+
message: string;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
}
|
|
121
192
|
interface Bucket {
|
|
122
193
|
id: string;
|
|
123
194
|
name: string;
|
|
@@ -228,6 +299,8 @@ declare class AuthHubClient {
|
|
|
228
299
|
readonly session: SessionModule;
|
|
229
300
|
/** Database CRUD operations */
|
|
230
301
|
readonly db: DbModule;
|
|
302
|
+
/** Database schema / DDL operations (create tables, add columns, etc.) */
|
|
303
|
+
readonly schema: SchemaModule;
|
|
231
304
|
/** File storage operations */
|
|
232
305
|
readonly storage: StorageModule;
|
|
233
306
|
/** OAuth social login helpers */
|
|
@@ -354,6 +427,28 @@ declare class DbModule {
|
|
|
354
427
|
/** Count rows matching a where clause */
|
|
355
428
|
count(table: string, where?: Record<string, unknown>): Promise<number>;
|
|
356
429
|
}
|
|
430
|
+
declare class SchemaModule {
|
|
431
|
+
private client;
|
|
432
|
+
constructor(client: AuthHubClient);
|
|
433
|
+
/** List all tables in the project database */
|
|
434
|
+
listTables(): Promise<SchemaListTablesResult>;
|
|
435
|
+
/** Create a new table (with id SERIAL PRIMARY KEY + created_at TIMESTAMP) */
|
|
436
|
+
createTable(table: string): Promise<SchemaCreateTableResult>;
|
|
437
|
+
/** Get column and constraint info for a table */
|
|
438
|
+
getTable(table: string): Promise<SchemaTableInfo>;
|
|
439
|
+
/** Drop a table (CASCADE) */
|
|
440
|
+
dropTable(table: string): Promise<SchemaDropTableResult>;
|
|
441
|
+
/** Add a column to an existing table */
|
|
442
|
+
addColumn(table: string, options: SchemaAddColumnOptions): Promise<SchemaDdlResult>;
|
|
443
|
+
/** Rename a column */
|
|
444
|
+
renameColumn(table: string, options: SchemaRenameColumnOptions): Promise<SchemaDdlResult>;
|
|
445
|
+
/** Drop a column */
|
|
446
|
+
dropColumn(table: string, column: string): Promise<SchemaDdlResult>;
|
|
447
|
+
/** Add a constraint (primary_key, unique, or foreign_key) */
|
|
448
|
+
addConstraint(table: string, options: SchemaAddConstraintOptions): Promise<SchemaDdlResult>;
|
|
449
|
+
/** Drop a named constraint */
|
|
450
|
+
dropConstraint(table: string, constraint: string): Promise<SchemaDdlResult>;
|
|
451
|
+
}
|
|
357
452
|
declare class StorageModule {
|
|
358
453
|
private client;
|
|
359
454
|
constructor(client: AuthHubClient);
|
|
@@ -455,4 +550,4 @@ declare class AuthHubError extends Error {
|
|
|
455
550
|
constructor(data: AuthHubErrorData);
|
|
456
551
|
}
|
|
457
552
|
|
|
458
|
-
export { AuthHubClient, type AuthHubConfig, AuthHubError, type AuthHubErrorData, type AuthResponse, type Bucket, type CreateBucketOptions, type DbCreateOptions, type DbDeleteOptions, type DbMutationResult, type DbReadOptions, type DbReadResult, type DbUpdateOptions, type ListObjectsOptions, LocalStorageTokenStore, MemoryTokenStore, type MessageResponse, type OAuthHashParams, type OAuthProvider, type OrderBy, RealtimeClient, type RealtimeConfig, type RealtimeMessage, type RealtimeMutationHandler, type RegisterResponse, type SessionLoginResult$1 as SessionLoginResult, type SessionResponse, type StorageListResult, type StorageObject, TokenManager, type TokenPair, type TokenStore, type UploadOptions, type User, type WhereClause, type WhereOperator };
|
|
553
|
+
export { AuthHubClient, type AuthHubConfig, AuthHubError, type AuthHubErrorData, type AuthResponse, type Bucket, type CreateBucketOptions, type DbCreateOptions, type DbDeleteOptions, type DbMutationResult, type DbReadOptions, type DbReadResult, type DbUpdateOptions, type ListObjectsOptions, LocalStorageTokenStore, MemoryTokenStore, type MessageResponse, type OAuthHashParams, type OAuthProvider, type OrderBy, RealtimeClient, type RealtimeConfig, type RealtimeMessage, type RealtimeMutationHandler, type RegisterResponse, type SchemaAddColumnOptions, type SchemaAddConstraintOptions, type SchemaColumn, type SchemaColumnType, type SchemaConstraint, type SchemaCreateTableResult, type SchemaDdlResult, type SchemaDropTableResult, type SchemaFkAction, type SchemaListTablesResult, type SchemaRenameColumnOptions, type SchemaTableInfo, type SessionLoginResult$1 as SessionLoginResult, type SessionResponse, type StorageListResult, type StorageObject, TokenManager, type TokenPair, type TokenStore, type UploadOptions, type User, type WhereClause, type WhereOperator };
|
package/dist/index.js
CHANGED
|
@@ -130,6 +130,7 @@ var AuthHubClient = class {
|
|
|
130
130
|
this.auth = new AuthModule(this);
|
|
131
131
|
this.session = new SessionModule(this);
|
|
132
132
|
this.db = new DbModule(this);
|
|
133
|
+
this.schema = new SchemaModule(this);
|
|
133
134
|
this.storage = new StorageModule(this);
|
|
134
135
|
this.oauth = new OAuthModule(this);
|
|
135
136
|
}
|
|
@@ -478,6 +479,67 @@ var DbModule = class {
|
|
|
478
479
|
return result.count;
|
|
479
480
|
}
|
|
480
481
|
};
|
|
482
|
+
var SchemaModule = class {
|
|
483
|
+
constructor(client) {
|
|
484
|
+
this.client = client;
|
|
485
|
+
}
|
|
486
|
+
/** List all tables in the project database */
|
|
487
|
+
async listTables() {
|
|
488
|
+
return this.client._apiRequest("/db/schema");
|
|
489
|
+
}
|
|
490
|
+
/** Create a new table (with id SERIAL PRIMARY KEY + created_at TIMESTAMP) */
|
|
491
|
+
async createTable(table) {
|
|
492
|
+
return this.client._apiRequest("/db/schema", {
|
|
493
|
+
method: "POST",
|
|
494
|
+
body: JSON.stringify({ table })
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/** Get column and constraint info for a table */
|
|
498
|
+
async getTable(table) {
|
|
499
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`);
|
|
500
|
+
}
|
|
501
|
+
/** Drop a table (CASCADE) */
|
|
502
|
+
async dropTable(table) {
|
|
503
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
504
|
+
method: "DELETE"
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/** Add a column to an existing table */
|
|
508
|
+
async addColumn(table, options) {
|
|
509
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
510
|
+
method: "POST",
|
|
511
|
+
body: JSON.stringify({ action: "add_column", ...options })
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/** Rename a column */
|
|
515
|
+
async renameColumn(table, options) {
|
|
516
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
517
|
+
method: "POST",
|
|
518
|
+
body: JSON.stringify({ action: "rename_column", ...options })
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
/** Drop a column */
|
|
522
|
+
async dropColumn(table, column) {
|
|
523
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
524
|
+
method: "POST",
|
|
525
|
+
body: JSON.stringify({ action: "drop_column", column })
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/** Add a constraint (primary_key, unique, or foreign_key) */
|
|
529
|
+
async addConstraint(table, options) {
|
|
530
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
body: JSON.stringify({ action: "add_constraint", ...options })
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/** Drop a named constraint */
|
|
536
|
+
async dropConstraint(table, constraint) {
|
|
537
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
538
|
+
method: "POST",
|
|
539
|
+
body: JSON.stringify({ action: "drop_constraint", constraint })
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
};
|
|
481
543
|
var StorageModule = class {
|
|
482
544
|
constructor(client) {
|
|
483
545
|
this.client = client;
|
package/dist/index.mjs
CHANGED
|
@@ -99,6 +99,7 @@ var AuthHubClient = class {
|
|
|
99
99
|
this.auth = new AuthModule(this);
|
|
100
100
|
this.session = new SessionModule(this);
|
|
101
101
|
this.db = new DbModule(this);
|
|
102
|
+
this.schema = new SchemaModule(this);
|
|
102
103
|
this.storage = new StorageModule(this);
|
|
103
104
|
this.oauth = new OAuthModule(this);
|
|
104
105
|
}
|
|
@@ -447,6 +448,67 @@ var DbModule = class {
|
|
|
447
448
|
return result.count;
|
|
448
449
|
}
|
|
449
450
|
};
|
|
451
|
+
var SchemaModule = class {
|
|
452
|
+
constructor(client) {
|
|
453
|
+
this.client = client;
|
|
454
|
+
}
|
|
455
|
+
/** List all tables in the project database */
|
|
456
|
+
async listTables() {
|
|
457
|
+
return this.client._apiRequest("/db/schema");
|
|
458
|
+
}
|
|
459
|
+
/** Create a new table (with id SERIAL PRIMARY KEY + created_at TIMESTAMP) */
|
|
460
|
+
async createTable(table) {
|
|
461
|
+
return this.client._apiRequest("/db/schema", {
|
|
462
|
+
method: "POST",
|
|
463
|
+
body: JSON.stringify({ table })
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/** Get column and constraint info for a table */
|
|
467
|
+
async getTable(table) {
|
|
468
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`);
|
|
469
|
+
}
|
|
470
|
+
/** Drop a table (CASCADE) */
|
|
471
|
+
async dropTable(table) {
|
|
472
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
473
|
+
method: "DELETE"
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
/** Add a column to an existing table */
|
|
477
|
+
async addColumn(table, options) {
|
|
478
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
479
|
+
method: "POST",
|
|
480
|
+
body: JSON.stringify({ action: "add_column", ...options })
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/** Rename a column */
|
|
484
|
+
async renameColumn(table, options) {
|
|
485
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
486
|
+
method: "POST",
|
|
487
|
+
body: JSON.stringify({ action: "rename_column", ...options })
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
/** Drop a column */
|
|
491
|
+
async dropColumn(table, column) {
|
|
492
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
493
|
+
method: "POST",
|
|
494
|
+
body: JSON.stringify({ action: "drop_column", column })
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/** Add a constraint (primary_key, unique, or foreign_key) */
|
|
498
|
+
async addConstraint(table, options) {
|
|
499
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
body: JSON.stringify({ action: "add_constraint", ...options })
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
/** Drop a named constraint */
|
|
505
|
+
async dropConstraint(table, constraint) {
|
|
506
|
+
return this.client._apiRequest(`/db/schema/${encodeURIComponent(table)}`, {
|
|
507
|
+
method: "POST",
|
|
508
|
+
body: JSON.stringify({ action: "drop_constraint", constraint })
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
};
|
|
450
512
|
var StorageModule = class {
|
|
451
513
|
constructor(client) {
|
|
452
514
|
this.client = client;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcimorra/authhub-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Official TypeScript SDK for Auth Hub — self-hosted authentication, OAuth social login, webhooks, realtime subscriptions, database, and storage as a service",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Official TypeScript SDK for Auth Hub — self-hosted authentication, OAuth social login, webhooks, realtime subscriptions, database, schema management, and storage as a service",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|