better-auth-studio 1.0.46-beta.8 → 1.0.46

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.
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAS9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA8I/E;AAwBD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAw1HR"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAS9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA8I/E;AAwBD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAw7HR"}
package/dist/routes.js CHANGED
@@ -3840,6 +3840,91 @@ export function createRoutes(authConfig, configPath, geoDbPath) {
3840
3840
  res.status(500).json({ hasResult: false, error: 'Failed to check status' });
3841
3841
  }
3842
3842
  });
3843
+ router.post('/api/tools/export', async (req, res) => {
3844
+ try {
3845
+ const { tables, format, limit } = req.body;
3846
+ if (!tables || !Array.isArray(tables) || tables.length === 0) {
3847
+ return res.status(400).json({ success: false, error: 'No tables specified' });
3848
+ }
3849
+ const exportLimit = Math.min(Math.max(parseInt(limit || '1000', 10), 1), 10000);
3850
+ const exportFormat = format === 'csv' ? 'csv' : 'json';
3851
+ const adapter = await getAuthAdapterWithConfig();
3852
+ if (!adapter || !adapter.findMany) {
3853
+ return res.status(500).json({ success: false, error: 'Auth adapter not available' });
3854
+ }
3855
+ const exportData = {};
3856
+ // Fetch data from each table
3857
+ for (const tableName of tables) {
3858
+ try {
3859
+ const data = await adapter.findMany({
3860
+ model: tableName,
3861
+ limit: exportLimit,
3862
+ });
3863
+ exportData[tableName] = data || [];
3864
+ }
3865
+ catch (error) {
3866
+ // If table doesn't exist or can't be accessed, skip it
3867
+ exportData[tableName] = [];
3868
+ }
3869
+ }
3870
+ let output;
3871
+ let filename;
3872
+ let contentType;
3873
+ if (exportFormat === 'csv') {
3874
+ // Convert to CSV
3875
+ const csvRows = [];
3876
+ for (const [tableName, rows] of Object.entries(exportData)) {
3877
+ if (rows.length === 0)
3878
+ continue;
3879
+ // Add table header
3880
+ csvRows.push(`\n=== ${tableName.toUpperCase()} ===\n`);
3881
+ // Get all unique keys from all rows
3882
+ const allKeys = new Set();
3883
+ rows.forEach((row) => {
3884
+ Object.keys(row).forEach((key) => allKeys.add(key));
3885
+ });
3886
+ const headers = Array.from(allKeys);
3887
+ // Write CSV header
3888
+ csvRows.push(headers.map((h) => `"${h}"`).join(','));
3889
+ // Write CSV rows
3890
+ rows.forEach((row) => {
3891
+ const values = headers.map((header) => {
3892
+ const value = row[header];
3893
+ if (value === null || value === undefined)
3894
+ return '';
3895
+ if (typeof value === 'object')
3896
+ return `"${JSON.stringify(value).replace(/"/g, '""')}"`;
3897
+ return `"${String(value).replace(/"/g, '""')}"`;
3898
+ });
3899
+ csvRows.push(values.join(','));
3900
+ });
3901
+ }
3902
+ output = csvRows.join('\n');
3903
+ filename = `better-auth-export-${new Date().toISOString().split('T')[0]}.csv`;
3904
+ contentType = 'text/csv';
3905
+ }
3906
+ else {
3907
+ // JSON format
3908
+ output = JSON.stringify(exportData, null, 2);
3909
+ filename = `better-auth-export-${new Date().toISOString().split('T')[0]}.json`;
3910
+ contentType = 'application/json';
3911
+ }
3912
+ res.json({
3913
+ success: true,
3914
+ data: output,
3915
+ filename,
3916
+ contentType,
3917
+ tables: tables,
3918
+ rowCounts: Object.fromEntries(Object.entries(exportData).map(([table, rows]) => [table, rows.length])),
3919
+ });
3920
+ }
3921
+ catch (error) {
3922
+ res.status(500).json({
3923
+ success: false,
3924
+ error: error instanceof Error ? error.message : 'Failed to export data',
3925
+ });
3926
+ }
3927
+ });
3843
3928
  return router;
3844
3929
  }
3845
3930
  //# sourceMappingURL=routes.js.map