dominus-sdk-nodejs-dev 1.2.4

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 (75) hide show
  1. package/LLM-GUIDE.md +537 -0
  2. package/README.md +585 -0
  3. package/dist/index.d.ts +191 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +224 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/cache.d.ts +112 -0
  8. package/dist/lib/cache.d.ts.map +1 -0
  9. package/dist/lib/cache.js +237 -0
  10. package/dist/lib/cache.js.map +1 -0
  11. package/dist/lib/client.d.ts +38 -0
  12. package/dist/lib/client.d.ts.map +1 -0
  13. package/dist/lib/client.js +425 -0
  14. package/dist/lib/client.js.map +1 -0
  15. package/dist/lib/config.d.ts +20 -0
  16. package/dist/lib/config.d.ts.map +1 -0
  17. package/dist/lib/config.js +32 -0
  18. package/dist/lib/config.js.map +1 -0
  19. package/dist/lib/crypto.d.ts +70 -0
  20. package/dist/lib/crypto.d.ts.map +1 -0
  21. package/dist/lib/crypto.js +95 -0
  22. package/dist/lib/crypto.js.map +1 -0
  23. package/dist/lib/errors.d.ts +77 -0
  24. package/dist/lib/errors.d.ts.map +1 -0
  25. package/dist/lib/errors.js +134 -0
  26. package/dist/lib/errors.js.map +1 -0
  27. package/dist/namespaces/auth.d.ts +237 -0
  28. package/dist/namespaces/auth.d.ts.map +1 -0
  29. package/dist/namespaces/auth.js +785 -0
  30. package/dist/namespaces/auth.js.map +1 -0
  31. package/dist/namespaces/courier.d.ts +67 -0
  32. package/dist/namespaces/courier.d.ts.map +1 -0
  33. package/dist/namespaces/courier.js +90 -0
  34. package/dist/namespaces/courier.js.map +1 -0
  35. package/dist/namespaces/db.d.ts +117 -0
  36. package/dist/namespaces/db.d.ts.map +1 -0
  37. package/dist/namespaces/db.js +149 -0
  38. package/dist/namespaces/db.js.map +1 -0
  39. package/dist/namespaces/ddl.d.ts +84 -0
  40. package/dist/namespaces/ddl.d.ts.map +1 -0
  41. package/dist/namespaces/ddl.js +211 -0
  42. package/dist/namespaces/ddl.js.map +1 -0
  43. package/dist/namespaces/files.d.ts +107 -0
  44. package/dist/namespaces/files.d.ts.map +1 -0
  45. package/dist/namespaces/files.js +161 -0
  46. package/dist/namespaces/files.js.map +1 -0
  47. package/dist/namespaces/health.d.ts +30 -0
  48. package/dist/namespaces/health.d.ts.map +1 -0
  49. package/dist/namespaces/health.js +66 -0
  50. package/dist/namespaces/health.js.map +1 -0
  51. package/dist/namespaces/logs.d.ts +97 -0
  52. package/dist/namespaces/logs.d.ts.map +1 -0
  53. package/dist/namespaces/logs.js +194 -0
  54. package/dist/namespaces/logs.js.map +1 -0
  55. package/dist/namespaces/open.d.ts +27 -0
  56. package/dist/namespaces/open.d.ts.map +1 -0
  57. package/dist/namespaces/open.js +46 -0
  58. package/dist/namespaces/open.js.map +1 -0
  59. package/dist/namespaces/portal.d.ts +172 -0
  60. package/dist/namespaces/portal.d.ts.map +1 -0
  61. package/dist/namespaces/portal.js +332 -0
  62. package/dist/namespaces/portal.js.map +1 -0
  63. package/dist/namespaces/redis.d.ts +144 -0
  64. package/dist/namespaces/redis.d.ts.map +1 -0
  65. package/dist/namespaces/redis.js +218 -0
  66. package/dist/namespaces/redis.js.map +1 -0
  67. package/dist/namespaces/secrets.d.ts +50 -0
  68. package/dist/namespaces/secrets.d.ts.map +1 -0
  69. package/dist/namespaces/secrets.js +93 -0
  70. package/dist/namespaces/secrets.js.map +1 -0
  71. package/dist/namespaces/secure.d.ts +102 -0
  72. package/dist/namespaces/secure.d.ts.map +1 -0
  73. package/dist/namespaces/secure.js +151 -0
  74. package/dist/namespaces/secure.js.map +1 -0
  75. package/package.json +45 -0
package/LLM-GUIDE.md ADDED
@@ -0,0 +1,537 @@
1
+ # CB Dominus SDK for Node.js - LLM Guide
2
+
3
+ This guide provides comprehensive documentation for LLMs to understand and use the Dominus SDK effectively.
4
+
5
+ ## Overview
6
+
7
+ The Dominus SDK is a TypeScript SDK for Node.js that provides access to the Dominus Orchestrator backend services. It uses a namespace-based API pattern with a singleton instance.
8
+
9
+ ## Installation & Setup
10
+
11
+ ```typescript
12
+ // Import the singleton
13
+ import { dominus } from 'dominus-sdk-nodejs';
14
+
15
+ // Token is read from DOMINUS_TOKEN environment variable
16
+ // Set it before using the SDK:
17
+ process.env.DOMINUS_TOKEN = "your-psk-token";
18
+ ```
19
+
20
+ ## Namespace Reference
21
+
22
+ ### dominus.secrets (Warden)
23
+
24
+ Secrets management operations.
25
+
26
+ ```typescript
27
+ // Get secret value
28
+ const value = await dominus.secrets.get("SECRET_KEY");
29
+
30
+ // Create/update secret
31
+ await dominus.secrets.upsert("KEY", "value", "optional comment");
32
+
33
+ // List secrets (optionally with prefix)
34
+ const secrets = await dominus.secrets.list("DB_");
35
+
36
+ // Delete secret
37
+ await dominus.secrets.delete("OLD_KEY");
38
+ ```
39
+
40
+ ### dominus.db (Scribe)
41
+
42
+ Database CRUD operations.
43
+
44
+ ```typescript
45
+ // List tables in a schema
46
+ const tables = await dominus.db.tables("public");
47
+
48
+ // List columns in a table
49
+ const columns = await dominus.db.columns("users", "public");
50
+
51
+ // Query with full options
52
+ const result = await dominus.db.query("users", {
53
+ schema: "public",
54
+ filters: { status: "active" },
55
+ sortBy: "created_at",
56
+ sortOrder: "DESC",
57
+ limit: 100,
58
+ offset: 0,
59
+ reason: "optional - required for secure tables",
60
+ actor: "user-id - required for secure tables"
61
+ });
62
+ // result.rows = array of records
63
+ // result.total = total count
64
+
65
+ // Insert row
66
+ const inserted = await dominus.db.insert("users", { name: "John" }, {
67
+ schema: "public",
68
+ reason: "optional",
69
+ actor: "optional"
70
+ });
71
+
72
+ // Update rows
73
+ const updated = await dominus.db.update(
74
+ "users",
75
+ { status: "inactive" }, // data to set
76
+ { id: "user-123" }, // filters (WHERE)
77
+ { schema: "public" }
78
+ );
79
+ // updated.affected_rows = number
80
+
81
+ // Delete rows
82
+ const deleted = await dominus.db.delete("users", { id: "user-123" }, {
83
+ schema: "public"
84
+ });
85
+ // deleted.affected_rows = number
86
+
87
+ // Bulk insert
88
+ const bulk = await dominus.db.bulkInsert("users", [
89
+ { name: "John" },
90
+ { name: "Jane" }
91
+ ], { schema: "public" });
92
+ // bulk.inserted_count = number
93
+ ```
94
+
95
+ ### dominus.redis (Whisperer)
96
+
97
+ Redis caching operations. TTL is required and enforced (60-86400 seconds).
98
+
99
+ ```typescript
100
+ // Set with TTL (required)
101
+ await dominus.redis.set("key", { data: "value" }, { ttl: 3600 });
102
+
103
+ // Get value
104
+ const value = await dominus.redis.get("key");
105
+
106
+ // Delete
107
+ await dominus.redis.delete("key");
108
+
109
+ // List keys by pattern
110
+ const keys = await dominus.redis.list({ pattern: "user:*" });
111
+
112
+ // Multi-get
113
+ const values = await dominus.redis.mget(["key1", "key2"]);
114
+
115
+ // Set if not exists (for locks)
116
+ const acquired = await dominus.redis.setnx("lock:key", "value", { ttl: 60 });
117
+
118
+ // Increment counter
119
+ await dominus.redis.incr("counter", 1);
120
+
121
+ // Hash operations
122
+ await dominus.redis.hset("hash", "field", "value", { ttl: 3600 });
123
+ const field = await dominus.redis.hget("hash", "field");
124
+ const allFields = await dominus.redis.hgetall("hash");
125
+ await dominus.redis.hdel("hash", "field");
126
+ ```
127
+
128
+ ### dominus.files (Archivist)
129
+
130
+ File storage operations via B2.
131
+
132
+ ```typescript
133
+ // Upload file
134
+ const result = await dominus.files.upload(
135
+ buffer, // Buffer
136
+ "filename.pdf",
137
+ {
138
+ contentType: "application/pdf",
139
+ category: "reports",
140
+ path: "2025/01/report.pdf",
141
+ tags: { department: "finance" },
142
+ compliance: false,
143
+ actor: "user-id",
144
+ retentionDays: 90
145
+ }
146
+ );
147
+ // result.id = file UUID
148
+ // result.path = stored path
149
+ // result.size = bytes
150
+
151
+ // Get download URL
152
+ const download = await dominus.files.download({
153
+ id: "file-uuid",
154
+ // OR use category + path:
155
+ // category: "reports",
156
+ // path: "2025/01/report.pdf",
157
+ expiresSeconds: 3600
158
+ });
159
+ // download.download_url = presigned URL
160
+ // download.expires_at = expiration timestamp
161
+
162
+ // Fetch content directly
163
+ const content = await dominus.files.fetch({ id: "file-uuid" });
164
+ // content.data = base64 encoded
165
+ // content.filename = original name
166
+ // content.content_type = mime type
167
+
168
+ // List files
169
+ const files = await dominus.files.list({
170
+ category: "reports",
171
+ prefix: "2025/",
172
+ limit: 100,
173
+ cursor: "optional-pagination-cursor"
174
+ });
175
+ // files.objects = array
176
+ // files.cursor = next page cursor
177
+ // files.count = number returned
178
+
179
+ // Delete file
180
+ await dominus.files.delete({ id: "file-uuid" });
181
+
182
+ // Move file
183
+ await dominus.files.move("file-uuid", {
184
+ newCategory: "archive",
185
+ newPath: "2024/report.pdf"
186
+ });
187
+
188
+ // Update metadata
189
+ await dominus.files.updateMeta("file-uuid", {
190
+ tags: { status: "reviewed" },
191
+ description: "Annual report"
192
+ });
193
+ ```
194
+
195
+ ### dominus.auth (Guardian)
196
+
197
+ Authentication and authorization management.
198
+
199
+ ```typescript
200
+ // Users
201
+ const users = await dominus.auth.listUsers();
202
+ const user = await dominus.auth.getUser("user-uuid");
203
+ const newUser = await dominus.auth.addUser({
204
+ username: "john",
205
+ password: "secret123", // hashed client-side
206
+ email: "john@example.com",
207
+ roleId: "role-uuid"
208
+ });
209
+ await dominus.auth.updateUser("user-uuid", { email: "new@email.com" });
210
+ await dominus.auth.deleteUser("user-uuid");
211
+
212
+ // Roles
213
+ const roles = await dominus.auth.listRoles();
214
+ const role = await dominus.auth.getRole("role-uuid");
215
+ const newRole = await dominus.auth.addRole({
216
+ name: "Editor",
217
+ scopeSlugs: ["read", "write"],
218
+ description: "Can edit content"
219
+ });
220
+ await dominus.auth.updateRole("role-uuid", { name: "Senior Editor" });
221
+ await dominus.auth.deleteRole("role-uuid");
222
+
223
+ // Scopes
224
+ const scopes = await dominus.auth.listScopes();
225
+ const scope = await dominus.auth.getScope("scope-uuid");
226
+ const newScope = await dominus.auth.addScope({
227
+ slug: "publish",
228
+ displayName: "Publish Content",
229
+ description: "Can publish content"
230
+ });
231
+ await dominus.auth.updateScope("scope-uuid", { display_name: "New Name" });
232
+ await dominus.auth.deleteScope("scope-uuid");
233
+
234
+ // Clients (service accounts)
235
+ const clients = await dominus.auth.listClients();
236
+ const client = await dominus.auth.getClient("client-uuid");
237
+ const newClient = await dominus.auth.addClient({
238
+ label: "API Client",
239
+ roleId: "role-uuid"
240
+ });
241
+ await dominus.auth.deleteClient("client-uuid");
242
+
243
+ // Tenants
244
+ const tenants = await dominus.auth.listTenants();
245
+ const tenant = await dominus.auth.getTenant("tenant-uuid");
246
+ const newTenant = await dominus.auth.addTenant({
247
+ name: "Acme Corp",
248
+ slug: "acme",
249
+ categoryId: "category-uuid"
250
+ });
251
+ await dominus.auth.updateTenant("tenant-uuid", { name: "Acme Inc" });
252
+ await dominus.auth.deleteTenant("tenant-uuid");
253
+
254
+ // Tenant Categories
255
+ const categories = await dominus.auth.listTenantCategories();
256
+ const category = await dominus.auth.getTenantCategory("category-uuid");
257
+
258
+ // Pages & Navigation
259
+ const pages = await dominus.auth.listPages();
260
+ const navigation = await dominus.auth.listNavigation();
261
+
262
+ // Secure Tables
263
+ const secureTables = await dominus.auth.listSecureTables();
264
+ await dominus.auth.addSecureTable({ schema: "tenant_acme", tableName: "patients" });
265
+ await dominus.auth.deleteSecureTable("table-uuid");
266
+ ```
267
+
268
+ ### dominus.ddl (Smith)
269
+
270
+ Schema DDL and migration operations.
271
+
272
+ ```typescript
273
+ // Schema DDL (single schema)
274
+ await dominus.ddl.createTable("orders", [
275
+ { name: "id", type: "UUID", constraints: ["PRIMARY KEY", "DEFAULT gen_random_uuid()"] },
276
+ { name: "user_id", type: "UUID", constraints: ["NOT NULL"] },
277
+ { name: "total", type: "DECIMAL(10,2)" },
278
+ { name: "status", type: "VARCHAR(50)", default: "'pending'" }
279
+ ], "public");
280
+
281
+ await dominus.ddl.dropTable("temp_table", "public");
282
+
283
+ await dominus.ddl.addColumn("orders", {
284
+ name: "notes",
285
+ type: "TEXT",
286
+ constraints: [],
287
+ default: undefined
288
+ }, "public");
289
+
290
+ await dominus.ddl.dropColumn("orders", "notes", "public");
291
+
292
+ await dominus.ddl.alterColumn("orders", "status", {
293
+ newType: "VARCHAR(100)",
294
+ newDefault: "'new'",
295
+ nullable: false
296
+ }, "public");
297
+
298
+ await dominus.ddl.createIndex("orders", "idx_orders_user", ["user_id"], {
299
+ unique: false,
300
+ schema: "public"
301
+ });
302
+
303
+ await dominus.ddl.dropIndex("idx_orders_user", "public");
304
+
305
+ // Category DDL (multi-schema - all tenants in category)
306
+ await dominus.ddl.categoryCreateTable("healthcare", "appointments", [
307
+ { name: "id", type: "UUID", constraints: ["PRIMARY KEY"] }
308
+ ]);
309
+
310
+ await dominus.ddl.categoryAddColumn("healthcare", "appointments", {
311
+ name: "notes",
312
+ type: "TEXT"
313
+ });
314
+
315
+ // Migrations
316
+ const migrations = await dominus.ddl.listMigrations("tenant_acme");
317
+ const categoryMigrations = await dominus.ddl.listCategoryMigrations("healthcare");
318
+ await dominus.ddl.applyMigration("tenant_acme", "migration-id");
319
+ await dominus.ddl.rollbackMigration("tenant_acme", "migration-id");
320
+
321
+ // Provisioning
322
+ await dominus.ddl.provisionTenantSchema("new_tenant", "healthcare");
323
+ await dominus.ddl.provisionTenantFromCategory("new_tenant", "healthcare");
324
+ ```
325
+
326
+ ### dominus.logs (Herald)
327
+
328
+ Structured logging operations.
329
+
330
+ ```typescript
331
+ // Log levels: debug, info, notice, warn, error, critical
332
+ await dominus.logs.debug("Debug message", { key: "value" }, "category");
333
+ await dominus.logs.info("Info message", { key: "value" });
334
+ await dominus.logs.notice("Notice message", { key: "value" });
335
+ await dominus.logs.warn("Warning message", { key: "value" });
336
+ await dominus.logs.error("Error message", { key: "value" }, {
337
+ category: "errors",
338
+ exception: new Error("Something failed")
339
+ });
340
+ await dominus.logs.critical("Critical message", { key: "value" }, {
341
+ exception: error
342
+ });
343
+
344
+ // Query logs
345
+ const logs = await dominus.logs.query({
346
+ level: "error",
347
+ category: "payments",
348
+ startTime: "2025-01-01T00:00:00Z",
349
+ endTime: "2025-01-31T23:59:59Z",
350
+ file: "payment.ts",
351
+ function: "processPayment",
352
+ search: "failed",
353
+ limit: 100,
354
+ // Admin only:
355
+ project: "my-project",
356
+ environment: "production"
357
+ });
358
+
359
+ // Batch logging
360
+ await dominus.logs.batch([
361
+ { level: "info", message: "First", context: {} },
362
+ { level: "info", message: "Second", context: {} }
363
+ ]);
364
+ ```
365
+
366
+ ### dominus.portal (Portal)
367
+
368
+ User authentication and session management.
369
+
370
+ ```typescript
371
+ // Authentication
372
+ const session = await dominus.portal.login("user@example.com", "password", "tenant-uuid");
373
+ const clientSession = await dominus.portal.loginClient("client-uuid", "psk", "tenant-uuid");
374
+ await dominus.portal.logout();
375
+ await dominus.portal.refresh();
376
+ const me = await dominus.portal.me();
377
+ await dominus.portal.switchTenant("other-tenant-uuid");
378
+
379
+ // Security
380
+ await dominus.portal.changePassword("current", "new");
381
+ await dominus.portal.requestPasswordReset("email@example.com");
382
+ await dominus.portal.confirmPasswordReset("token", "newPassword");
383
+ const sessions = await dominus.portal.listSessions();
384
+ await dominus.portal.revokeSession("session-uuid");
385
+ await dominus.portal.revokeAllSessions();
386
+
387
+ // Profile
388
+ const profile = await dominus.portal.getProfile();
389
+ await dominus.portal.updateProfile({
390
+ displayName: "John Doe",
391
+ avatarUrl: "https://...",
392
+ bio: "Developer",
393
+ phone: "+1234567890",
394
+ extra: { custom: "data" }
395
+ });
396
+ const prefs = await dominus.portal.getPreferences();
397
+ await dominus.portal.updatePreferences({
398
+ theme: "dark",
399
+ language: "en",
400
+ timezone: "America/New_York",
401
+ sidebarCollapsed: false,
402
+ notificationsEnabled: true,
403
+ emailNotifications: true,
404
+ extra: { custom: "prefs" }
405
+ });
406
+
407
+ // Navigation
408
+ const nav = await dominus.portal.getNavigation();
409
+ const access = await dominus.portal.checkPageAccess("/admin/users");
410
+ // access.allowed = boolean
411
+ // access.reason = string (if denied)
412
+
413
+ // Registration
414
+ await dominus.portal.register("username", "email@example.com", "password", "tenant-uuid");
415
+ await dominus.portal.verifyEmail("token");
416
+ await dominus.portal.resendVerification("email@example.com");
417
+ await dominus.portal.acceptInvitation("token", "password");
418
+ ```
419
+
420
+ ### dominus.courier (Courier)
421
+
422
+ Email delivery via Postmark.
423
+
424
+ ```typescript
425
+ // Send with template
426
+ const result = await dominus.courier.send(
427
+ "template-alias",
428
+ "recipient@example.com",
429
+ "sender@myapp.com",
430
+ { name: "John", product_name: "MyApp" },
431
+ { tag: "welcome", replyTo: "support@myapp.com" }
432
+ );
433
+ // result.to, result.message_id, result.submitted_at
434
+
435
+ // Convenience methods
436
+ await dominus.courier.sendWelcome(
437
+ "user@example.com",
438
+ "noreply@myapp.com",
439
+ { name: "John", productName: "MyApp", actionUrl: "https://..." }
440
+ );
441
+
442
+ await dominus.courier.sendPasswordReset(
443
+ "user@example.com",
444
+ "noreply@myapp.com",
445
+ { name: "John", resetUrl: "https://...", productName: "MyApp" }
446
+ );
447
+
448
+ await dominus.courier.sendEmailVerification(
449
+ "user@example.com",
450
+ "noreply@myapp.com",
451
+ { name: "John", verifyUrl: "https://...", productName: "MyApp" }
452
+ );
453
+
454
+ await dominus.courier.sendInvitation(
455
+ "invitee@example.com",
456
+ "noreply@myapp.com",
457
+ {
458
+ name: "Jane",
459
+ inviteUrl: "https://...",
460
+ inviterName: "John",
461
+ productName: "MyApp"
462
+ }
463
+ );
464
+ ```
465
+
466
+ ### dominus.open (Scribe Open)
467
+
468
+ Direct database access (use with caution).
469
+
470
+ ```typescript
471
+ // Get PostgreSQL connection DSN
472
+ const dsn = await dominus.open.dsn();
473
+
474
+ // Execute raw SQL
475
+ const result = await dominus.open.execute(
476
+ "SELECT * FROM users WHERE id = $1",
477
+ { "1": "user-uuid" }
478
+ );
479
+ ```
480
+
481
+ ### dominus.health (Health)
482
+
483
+ Service health checks.
484
+
485
+ ```typescript
486
+ // Full health check with latency
487
+ const status = await dominus.health.check();
488
+ // status.status = "healthy" | "unhealthy"
489
+ // status.latency_ms = number
490
+
491
+ // Quick ping
492
+ const ping = await dominus.health.ping();
493
+ // ping.status = "ok"
494
+
495
+ // Warmup (triggers cold start)
496
+ await dominus.health.warmup();
497
+ ```
498
+
499
+ ## Error Handling
500
+
501
+ ```typescript
502
+ import {
503
+ DominusError,
504
+ AuthenticationError,
505
+ AuthorizationError,
506
+ NotFoundError,
507
+ ValidationError,
508
+ ConflictError,
509
+ ServiceError,
510
+ ConnectionError,
511
+ TimeoutError,
512
+ SecureTableError,
513
+ } from '@carebridge/dominus-sdk';
514
+
515
+ try {
516
+ await dominus.db.query("secure_table");
517
+ } catch (error) {
518
+ if (error instanceof SecureTableError) {
519
+ // Need reason and actor for secure tables
520
+ } else if (error instanceof NotFoundError) {
521
+ // Resource not found
522
+ } else if (error instanceof AuthorizationError) {
523
+ // Permission denied
524
+ } else if (error instanceof DominusError) {
525
+ // Generic error with statusCode, message, details
526
+ }
527
+ }
528
+ ```
529
+
530
+ ## Key Patterns
531
+
532
+ 1. **Singleton import**: Always use `import { dominus } from '@carebridge/dominus-sdk'`
533
+ 2. **Async/await**: All methods are async
534
+ 3. **Schema parameter**: Database operations support schema parameter for multi-tenancy
535
+ 4. **Secure tables**: Require `reason` and `actor` parameters for audit trail
536
+ 5. **TTL required**: Redis operations require TTL (60-86400 seconds)
537
+ 6. **Error types**: Use specific error classes for precise error handling