@fluxbase/sdk 0.0.1-rc.2 → 0.0.1-rc.6

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/dist/index.cjs CHANGED
@@ -1213,11 +1213,429 @@ var AppSettingsManager = class {
1213
1213
  security: { enable_global_rate_limit: enabled }
1214
1214
  });
1215
1215
  }
1216
+ /**
1217
+ * Configure SMTP email provider
1218
+ *
1219
+ * Convenience method to set up SMTP email delivery.
1220
+ *
1221
+ * @param config - SMTP configuration
1222
+ * @returns Promise resolving to AppSettings
1223
+ *
1224
+ * @example
1225
+ * ```typescript
1226
+ * await client.admin.settings.app.configureSMTP({
1227
+ * host: 'smtp.gmail.com',
1228
+ * port: 587,
1229
+ * username: 'your-email@gmail.com',
1230
+ * password: 'your-app-password',
1231
+ * use_tls: true,
1232
+ * from_address: 'noreply@yourapp.com',
1233
+ * from_name: 'Your App'
1234
+ * })
1235
+ * ```
1236
+ */
1237
+ async configureSMTP(config) {
1238
+ return await this.update({
1239
+ email: {
1240
+ enabled: true,
1241
+ provider: "smtp",
1242
+ from_address: config.from_address,
1243
+ from_name: config.from_name,
1244
+ reply_to_address: config.reply_to_address,
1245
+ smtp: {
1246
+ host: config.host,
1247
+ port: config.port,
1248
+ username: config.username,
1249
+ password: config.password,
1250
+ use_tls: config.use_tls
1251
+ }
1252
+ }
1253
+ });
1254
+ }
1255
+ /**
1256
+ * Configure SendGrid email provider
1257
+ *
1258
+ * Convenience method to set up SendGrid email delivery.
1259
+ *
1260
+ * @param apiKey - SendGrid API key
1261
+ * @param options - Optional from address, name, and reply-to
1262
+ * @returns Promise resolving to AppSettings
1263
+ *
1264
+ * @example
1265
+ * ```typescript
1266
+ * await client.admin.settings.app.configureSendGrid('SG.xxx', {
1267
+ * from_address: 'noreply@yourapp.com',
1268
+ * from_name: 'Your App'
1269
+ * })
1270
+ * ```
1271
+ */
1272
+ async configureSendGrid(apiKey, options) {
1273
+ return await this.update({
1274
+ email: {
1275
+ enabled: true,
1276
+ provider: "sendgrid",
1277
+ from_address: options?.from_address,
1278
+ from_name: options?.from_name,
1279
+ reply_to_address: options?.reply_to_address,
1280
+ sendgrid: {
1281
+ api_key: apiKey
1282
+ }
1283
+ }
1284
+ });
1285
+ }
1286
+ /**
1287
+ * Configure Mailgun email provider
1288
+ *
1289
+ * Convenience method to set up Mailgun email delivery.
1290
+ *
1291
+ * @param apiKey - Mailgun API key
1292
+ * @param domain - Mailgun domain
1293
+ * @param options - Optional EU region flag and email addresses
1294
+ * @returns Promise resolving to AppSettings
1295
+ *
1296
+ * @example
1297
+ * ```typescript
1298
+ * await client.admin.settings.app.configureMailgun('key-xxx', 'mg.yourapp.com', {
1299
+ * eu_region: false,
1300
+ * from_address: 'noreply@yourapp.com',
1301
+ * from_name: 'Your App'
1302
+ * })
1303
+ * ```
1304
+ */
1305
+ async configureMailgun(apiKey, domain, options) {
1306
+ return await this.update({
1307
+ email: {
1308
+ enabled: true,
1309
+ provider: "mailgun",
1310
+ from_address: options?.from_address,
1311
+ from_name: options?.from_name,
1312
+ reply_to_address: options?.reply_to_address,
1313
+ mailgun: {
1314
+ api_key: apiKey,
1315
+ domain,
1316
+ eu_region: options?.eu_region ?? false
1317
+ }
1318
+ }
1319
+ });
1320
+ }
1321
+ /**
1322
+ * Configure AWS SES email provider
1323
+ *
1324
+ * Convenience method to set up AWS SES email delivery.
1325
+ *
1326
+ * @param accessKeyId - AWS access key ID
1327
+ * @param secretAccessKey - AWS secret access key
1328
+ * @param region - AWS region (e.g., 'us-east-1')
1329
+ * @param options - Optional email addresses
1330
+ * @returns Promise resolving to AppSettings
1331
+ *
1332
+ * @example
1333
+ * ```typescript
1334
+ * await client.admin.settings.app.configureSES(
1335
+ * 'AKIAIOSFODNN7EXAMPLE',
1336
+ * 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
1337
+ * 'us-east-1',
1338
+ * {
1339
+ * from_address: 'noreply@yourapp.com',
1340
+ * from_name: 'Your App'
1341
+ * }
1342
+ * )
1343
+ * ```
1344
+ */
1345
+ async configureSES(accessKeyId, secretAccessKey, region, options) {
1346
+ return await this.update({
1347
+ email: {
1348
+ enabled: true,
1349
+ provider: "ses",
1350
+ from_address: options?.from_address,
1351
+ from_name: options?.from_name,
1352
+ reply_to_address: options?.reply_to_address,
1353
+ ses: {
1354
+ access_key_id: accessKeyId,
1355
+ secret_access_key: secretAccessKey,
1356
+ region
1357
+ }
1358
+ }
1359
+ });
1360
+ }
1361
+ /**
1362
+ * Enable or disable email functionality
1363
+ *
1364
+ * Convenience method to toggle email system on/off.
1365
+ *
1366
+ * @param enabled - Whether to enable email
1367
+ * @returns Promise resolving to AppSettings
1368
+ *
1369
+ * @example
1370
+ * ```typescript
1371
+ * await client.admin.settings.app.setEmailEnabled(true)
1372
+ * ```
1373
+ */
1374
+ async setEmailEnabled(enabled) {
1375
+ return await this.update({
1376
+ email: { enabled }
1377
+ });
1378
+ }
1379
+ /**
1380
+ * Configure password complexity requirements
1381
+ *
1382
+ * Convenience method to set password validation rules.
1383
+ *
1384
+ * @param requirements - Password complexity requirements
1385
+ * @returns Promise resolving to AppSettings
1386
+ *
1387
+ * @example
1388
+ * ```typescript
1389
+ * await client.admin.settings.app.setPasswordComplexity({
1390
+ * min_length: 12,
1391
+ * require_uppercase: true,
1392
+ * require_lowercase: true,
1393
+ * require_number: true,
1394
+ * require_special: true
1395
+ * })
1396
+ * ```
1397
+ */
1398
+ async setPasswordComplexity(requirements) {
1399
+ return await this.update({
1400
+ authentication: {
1401
+ password_min_length: requirements.min_length,
1402
+ password_require_uppercase: requirements.require_uppercase,
1403
+ password_require_lowercase: requirements.require_lowercase,
1404
+ password_require_number: requirements.require_number,
1405
+ password_require_special: requirements.require_special
1406
+ }
1407
+ });
1408
+ }
1409
+ /**
1410
+ * Configure session settings
1411
+ *
1412
+ * Convenience method to set session timeout and limits.
1413
+ *
1414
+ * @param timeoutMinutes - Session timeout in minutes (0 for no timeout)
1415
+ * @param maxSessionsPerUser - Maximum concurrent sessions per user (0 for unlimited)
1416
+ * @returns Promise resolving to AppSettings
1417
+ *
1418
+ * @example
1419
+ * ```typescript
1420
+ * // 30 minute sessions, max 3 devices per user
1421
+ * await client.admin.settings.app.setSessionSettings(30, 3)
1422
+ * ```
1423
+ */
1424
+ async setSessionSettings(timeoutMinutes, maxSessionsPerUser) {
1425
+ return await this.update({
1426
+ authentication: {
1427
+ session_timeout_minutes: timeoutMinutes,
1428
+ max_sessions_per_user: maxSessionsPerUser
1429
+ }
1430
+ });
1431
+ }
1432
+ /**
1433
+ * Enable or disable email verification requirement
1434
+ *
1435
+ * Convenience method to require email verification for new signups.
1436
+ *
1437
+ * @param required - Whether to require email verification
1438
+ * @returns Promise resolving to AppSettings
1439
+ *
1440
+ * @example
1441
+ * ```typescript
1442
+ * await client.admin.settings.app.setEmailVerificationRequired(true)
1443
+ * ```
1444
+ */
1445
+ async setEmailVerificationRequired(required) {
1446
+ return await this.update({
1447
+ authentication: { require_email_verification: required }
1448
+ });
1449
+ }
1450
+ };
1451
+ var CustomSettingsManager = class {
1452
+ constructor(fetch2) {
1453
+ this.fetch = fetch2;
1454
+ }
1455
+ /**
1456
+ * Create a new custom setting
1457
+ *
1458
+ * @param request - Custom setting creation request
1459
+ * @returns Promise resolving to CustomSetting
1460
+ *
1461
+ * @example
1462
+ * ```typescript
1463
+ * const setting = await client.admin.settings.custom.create({
1464
+ * key: 'api.quotas',
1465
+ * value: { free: 1000, pro: 10000, enterprise: 100000 },
1466
+ * value_type: 'json',
1467
+ * description: 'API request quotas by tier',
1468
+ * metadata: { category: 'billing' }
1469
+ * })
1470
+ * ```
1471
+ */
1472
+ async create(request) {
1473
+ return await this.fetch.post("/api/v1/admin/settings/custom", request);
1474
+ }
1475
+ /**
1476
+ * List all custom settings
1477
+ *
1478
+ * @returns Promise resolving to ListCustomSettingsResponse
1479
+ *
1480
+ * @example
1481
+ * ```typescript
1482
+ * const response = await client.admin.settings.custom.list()
1483
+ * console.log(response.settings)
1484
+ * ```
1485
+ */
1486
+ async list() {
1487
+ const settings = await this.fetch.get("/api/v1/admin/settings/custom");
1488
+ return { settings: Array.isArray(settings) ? settings : [] };
1489
+ }
1490
+ /**
1491
+ * Get a specific custom setting by key
1492
+ *
1493
+ * @param key - Setting key (e.g., 'feature.dark_mode')
1494
+ * @returns Promise resolving to CustomSetting
1495
+ *
1496
+ * @example
1497
+ * ```typescript
1498
+ * const setting = await client.admin.settings.custom.get('feature.dark_mode')
1499
+ * console.log(setting.value)
1500
+ * ```
1501
+ */
1502
+ async get(key) {
1503
+ return await this.fetch.get(`/api/v1/admin/settings/custom/${key}`);
1504
+ }
1505
+ /**
1506
+ * Update an existing custom setting
1507
+ *
1508
+ * @param key - Setting key
1509
+ * @param request - Update request with new values
1510
+ * @returns Promise resolving to CustomSetting
1511
+ *
1512
+ * @example
1513
+ * ```typescript
1514
+ * const updated = await client.admin.settings.custom.update('feature.dark_mode', {
1515
+ * value: { enabled: false },
1516
+ * description: 'Updated description'
1517
+ * })
1518
+ * ```
1519
+ */
1520
+ async update(key, request) {
1521
+ return await this.fetch.put(`/api/v1/admin/settings/custom/${key}`, request);
1522
+ }
1523
+ /**
1524
+ * Delete a custom setting
1525
+ *
1526
+ * @param key - Setting key to delete
1527
+ * @returns Promise<void>
1528
+ *
1529
+ * @example
1530
+ * ```typescript
1531
+ * await client.admin.settings.custom.delete('feature.dark_mode')
1532
+ * ```
1533
+ */
1534
+ async delete(key) {
1535
+ await this.fetch.delete(`/api/v1/admin/settings/custom/${key}`);
1536
+ }
1537
+ };
1538
+ var EmailTemplateManager = class {
1539
+ constructor(fetch2) {
1540
+ this.fetch = fetch2;
1541
+ }
1542
+ /**
1543
+ * List all email templates
1544
+ *
1545
+ * @returns Promise resolving to ListEmailTemplatesResponse
1546
+ *
1547
+ * @example
1548
+ * ```typescript
1549
+ * const response = await client.admin.emailTemplates.list()
1550
+ * console.log(response.templates)
1551
+ * ```
1552
+ */
1553
+ async list() {
1554
+ const templates = await this.fetch.get("/api/v1/admin/email/templates");
1555
+ return { templates: Array.isArray(templates) ? templates : [] };
1556
+ }
1557
+ /**
1558
+ * Get a specific email template by type
1559
+ *
1560
+ * @param type - Template type (magic_link | verify_email | reset_password | invite_user)
1561
+ * @returns Promise resolving to EmailTemplate
1562
+ *
1563
+ * @example
1564
+ * ```typescript
1565
+ * const template = await client.admin.emailTemplates.get('magic_link')
1566
+ * console.log(template.subject)
1567
+ * console.log(template.html_body)
1568
+ * ```
1569
+ */
1570
+ async get(type) {
1571
+ return await this.fetch.get(`/api/v1/admin/email/templates/${type}`);
1572
+ }
1573
+ /**
1574
+ * Update an email template
1575
+ *
1576
+ * Available template variables:
1577
+ * - magic_link: {{.MagicLink}}, {{.AppName}}, {{.ExpiryMinutes}}
1578
+ * - verify_email: {{.VerificationLink}}, {{.AppName}}
1579
+ * - reset_password: {{.ResetLink}}, {{.AppName}}, {{.ExpiryMinutes}}
1580
+ * - invite_user: {{.InviteLink}}, {{.AppName}}, {{.InviterName}}
1581
+ *
1582
+ * @param type - Template type to update
1583
+ * @param request - Update request with subject, html_body, and optional text_body
1584
+ * @returns Promise resolving to EmailTemplate
1585
+ *
1586
+ * @example
1587
+ * ```typescript
1588
+ * const updated = await client.admin.emailTemplates.update('magic_link', {
1589
+ * subject: 'Your Magic Link - Sign in to {{.AppName}}',
1590
+ * html_body: '<html><body><h1>Welcome!</h1><a href="{{.MagicLink}}">Sign In</a></body></html>',
1591
+ * text_body: 'Click here to sign in: {{.MagicLink}}'
1592
+ * })
1593
+ * ```
1594
+ */
1595
+ async update(type, request) {
1596
+ return await this.fetch.put(`/api/v1/admin/email/templates/${type}`, request);
1597
+ }
1598
+ /**
1599
+ * Reset an email template to default
1600
+ *
1601
+ * Removes any customizations and restores the template to its original state.
1602
+ *
1603
+ * @param type - Template type to reset
1604
+ * @returns Promise resolving to EmailTemplate - The default template
1605
+ *
1606
+ * @example
1607
+ * ```typescript
1608
+ * const defaultTemplate = await client.admin.emailTemplates.reset('magic_link')
1609
+ * ```
1610
+ */
1611
+ async reset(type) {
1612
+ return await this.fetch.post(`/api/v1/admin/email/templates/${type}/reset`, {});
1613
+ }
1614
+ /**
1615
+ * Send a test email using the template
1616
+ *
1617
+ * Useful for previewing template changes before deploying to production.
1618
+ *
1619
+ * @param type - Template type to test
1620
+ * @param recipientEmail - Email address to send test to
1621
+ * @returns Promise<void>
1622
+ *
1623
+ * @example
1624
+ * ```typescript
1625
+ * await client.admin.emailTemplates.test('magic_link', 'test@example.com')
1626
+ * ```
1627
+ */
1628
+ async test(type, recipientEmail) {
1629
+ await this.fetch.post(`/api/v1/admin/email/templates/${type}/test`, {
1630
+ recipient_email: recipientEmail
1631
+ });
1632
+ }
1216
1633
  };
1217
1634
  var FluxbaseSettings = class {
1218
1635
  constructor(fetch2) {
1219
1636
  this.system = new SystemSettingsManager(fetch2);
1220
1637
  this.app = new AppSettingsManager(fetch2);
1638
+ this.custom = new CustomSettingsManager(fetch2);
1221
1639
  }
1222
1640
  };
1223
1641
 
@@ -2240,6 +2658,7 @@ var FluxbaseAdmin = class {
2240
2658
  this.oauth = new FluxbaseOAuth(fetch2);
2241
2659
  this.impersonation = new ImpersonationManager(fetch2);
2242
2660
  this.management = new FluxbaseManagement(fetch2);
2661
+ this.emailTemplates = new EmailTemplateManager(fetch2);
2243
2662
  }
2244
2663
  /**
2245
2664
  * Set admin authentication token
@@ -3238,6 +3657,7 @@ exports.APIKeysManager = APIKeysManager;
3238
3657
  exports.AppSettingsManager = AppSettingsManager;
3239
3658
  exports.AuthSettingsManager = AuthSettingsManager;
3240
3659
  exports.DDLManager = DDLManager;
3660
+ exports.EmailTemplateManager = EmailTemplateManager;
3241
3661
  exports.FluxbaseAdmin = FluxbaseAdmin;
3242
3662
  exports.FluxbaseAuth = FluxbaseAuth;
3243
3663
  exports.FluxbaseClient = FluxbaseClient;