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

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