@rimori/client 2.5.32 → 2.5.33

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 (28) hide show
  1. package/dist/cli/scripts/init/dev-registration.js +118 -136
  2. package/dist/cli/scripts/init/main.js +116 -127
  3. package/dist/cli/scripts/init/package-setup.js +15 -2
  4. package/dist/cli/scripts/release/detect-translation-languages.js +24 -35
  5. package/dist/cli/scripts/release/release-config-upload.js +87 -100
  6. package/dist/cli/scripts/release/release-db-update.js +70 -81
  7. package/dist/cli/scripts/release/release-file-upload.js +75 -91
  8. package/dist/cli/scripts/release/release-prompts-upload.js +60 -72
  9. package/dist/cli/scripts/release/release.js +20 -31
  10. package/dist/controller/AccomplishmentController.js +12 -12
  11. package/dist/controller/AudioController.js +15 -33
  12. package/dist/controller/TranslationController.js +108 -118
  13. package/dist/fromRimori/EventBus.js +20 -31
  14. package/dist/plugin/CommunicationHandler.js +73 -81
  15. package/dist/plugin/Logger.js +71 -83
  16. package/dist/plugin/RimoriClient.js +31 -31
  17. package/dist/plugin/StandaloneClient.js +81 -98
  18. package/dist/plugin/TTS/ChunkedAudioPlayer.js +31 -41
  19. package/dist/plugin/TTS/MessageSender.js +28 -37
  20. package/dist/plugin/module/AIModule.js +215 -237
  21. package/dist/plugin/module/DbModule.js +22 -31
  22. package/dist/plugin/module/EventModule.js +23 -32
  23. package/dist/plugin/module/ExerciseModule.js +42 -56
  24. package/dist/plugin/module/PluginModule.js +97 -106
  25. package/dist/plugin/module/SharedContentController.js +170 -207
  26. package/dist/plugin/module/StorageModule.js +18 -29
  27. package/dist/worker/WorkerSetup.js +23 -34
  28. package/package.json +1 -1
@@ -1,43 +1,32 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import fs from 'fs';
11
2
  /**
12
3
  * Detect available translation languages from public/locales directory
13
4
  * @returns Promise<string[]> Array of language codes found in the locales directory
14
5
  */
15
- export function detectTranslationLanguages() {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const localesPath = './public/locales';
18
- try {
19
- yield fs.promises.access(localesPath);
20
- }
21
- catch (e) {
22
- console.log('⚠️ No locales directory found, no translations available');
23
- return [];
24
- }
25
- try {
26
- const files = yield fs.promises.readdir(localesPath);
27
- // Filter out local- files and only include .json files
28
- const translationFiles = files.filter((file) => file.endsWith('.json') && !file.startsWith('local-'));
29
- if (translationFiles.length === 0) {
30
- console.log('⚠️ No translation files found (excluding local- files)');
31
- return [];
32
- }
33
- // Extract language codes from filenames (e.g., en.json -> en)
34
- const languages = translationFiles.map((file) => file.replace('.json', ''));
35
- console.log(`🌐 Found ${languages.length} translation languages: ${languages.join(', ')}`);
36
- return languages;
37
- }
38
- catch (error) {
39
- console.error(`❌ Error reading locales directory:`, error.message);
6
+ export async function detectTranslationLanguages() {
7
+ const localesPath = './public/locales';
8
+ try {
9
+ await fs.promises.access(localesPath);
10
+ }
11
+ catch (e) {
12
+ console.log('⚠️ No locales directory found, no translations available');
13
+ return [];
14
+ }
15
+ try {
16
+ const files = await fs.promises.readdir(localesPath);
17
+ // Filter out local- files and only include .json files
18
+ const translationFiles = files.filter((file) => file.endsWith('.json') && !file.startsWith('local-'));
19
+ if (translationFiles.length === 0) {
20
+ console.log('⚠️ No translation files found (excluding local- files)');
40
21
  return [];
41
22
  }
42
- });
23
+ // Extract language codes from filenames (e.g., en.json -> en)
24
+ const languages = translationFiles.map((file) => file.replace('.json', ''));
25
+ console.log(`🌐 Found ${languages.length} translation languages: ${languages.join(', ')}`);
26
+ return languages;
27
+ }
28
+ catch (error) {
29
+ console.error(`❌ Error reading locales directory:`, error.message);
30
+ return [];
31
+ }
43
32
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import fs from 'fs';
11
2
  import path from 'path';
12
3
  import ts from 'typescript';
@@ -15,106 +6,102 @@ import { detectTranslationLanguages } from './detect-translation-languages.js';
15
6
  * Read and send the rimori configuration to the release endpoint
16
7
  * @param config - Configuration object
17
8
  */
18
- export function sendConfiguration(config) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const configPath = path.resolve('./rimori/rimori.config.ts');
21
- // Check if config file exists
9
+ export async function sendConfiguration(config) {
10
+ const configPath = path.resolve('./rimori/rimori.config.ts');
11
+ // Check if config file exists
12
+ try {
13
+ await fs.promises.access(configPath);
14
+ }
15
+ catch (e) {
16
+ throw new Error('Could not find rimori.config.ts in ./rimori/ directory');
17
+ }
18
+ try {
19
+ let configObject;
20
+ // Use TypeScript compiler to transpile and load
21
+ const configContent = await fs.promises.readFile(configPath, 'utf8');
22
+ // Transpile TypeScript to JavaScript
23
+ const result = ts.transpile(configContent, {
24
+ target: ts.ScriptTarget.ES2020,
25
+ module: ts.ModuleKind.ES2020,
26
+ });
27
+ // Create a temporary file to import the transpiled code
28
+ const tempFile = path.join(process.cwd(), 'temp_config.js');
29
+ await fs.promises.writeFile(tempFile, result);
22
30
  try {
23
- yield fs.promises.access(configPath);
31
+ // Use dynamic import to load the config
32
+ const config = await import(`file://${tempFile}`);
33
+ configObject = config.default || config;
34
+ // Clean up temp file
35
+ await fs.promises.unlink(tempFile);
24
36
  }
25
- catch (e) {
26
- throw new Error('Could not find rimori.config.ts in ./rimori/ directory');
37
+ catch (error) {
38
+ // Clean up temp file even on error
39
+ try {
40
+ await fs.promises.unlink(tempFile);
41
+ }
42
+ catch (e) { }
43
+ throw error;
44
+ }
45
+ if (!configObject) {
46
+ throw new Error('Configuration object is empty or undefined');
27
47
  }
48
+ // Detect available translation languages
49
+ const availableLanguages = await detectTranslationLanguages();
50
+ console.log(`🚀 Sending configuration...`);
51
+ const requestBody = {
52
+ config: configObject,
53
+ version: config.version,
54
+ plugin_id: config.plugin_id,
55
+ release_channel: config.release_channel,
56
+ rimori_client_version: config.rimori_client_version,
57
+ provided_languages: availableLanguages.join(','),
58
+ };
28
59
  try {
29
- let configObject;
30
- // Use TypeScript compiler to transpile and load
31
- const configContent = yield fs.promises.readFile(configPath, 'utf8');
32
- // Transpile TypeScript to JavaScript
33
- const result = ts.transpile(configContent, {
34
- target: ts.ScriptTarget.ES2020,
35
- module: ts.ModuleKind.ES2020,
60
+ const response = await fetch(`${config.domain}/release`, {
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ Authorization: `Bearer ${config.token}`,
65
+ },
66
+ body: JSON.stringify(requestBody),
36
67
  });
37
- // Create a temporary file to import the transpiled code
38
- const tempFile = path.join(process.cwd(), 'temp_config.js');
39
- yield fs.promises.writeFile(tempFile, result);
40
- try {
41
- // Use dynamic import to load the config
42
- const config = yield import(`file://${tempFile}`);
43
- configObject = config.default || config;
44
- // Clean up temp file
45
- yield fs.promises.unlink(tempFile);
46
- }
47
- catch (error) {
48
- // Clean up temp file even on error
49
- try {
50
- yield fs.promises.unlink(tempFile);
51
- }
52
- catch (e) { }
53
- throw error;
68
+ const responseText = await response.text();
69
+ console.log('Configuration response status:', response.status);
70
+ console.log('Configuration response text:', responseText);
71
+ const responseData = JSON.parse(responseText);
72
+ if (response.ok) {
73
+ console.log('✅ Configuration deployed successfully!');
74
+ return responseData.release_id;
54
75
  }
55
- if (!configObject) {
56
- throw new Error('Configuration object is empty or undefined');
57
- }
58
- // Detect available translation languages
59
- const availableLanguages = yield detectTranslationLanguages();
60
- console.log(`🚀 Sending configuration...`);
61
- const requestBody = {
62
- config: configObject,
63
- version: config.version,
64
- plugin_id: config.plugin_id,
65
- release_channel: config.release_channel,
66
- rimori_client_version: config.rimori_client_version,
67
- provided_languages: availableLanguages.join(','),
68
- };
69
- try {
70
- const response = yield fetch(`${config.domain}/release`, {
71
- method: 'POST',
72
- headers: {
73
- 'Content-Type': 'application/json',
74
- Authorization: `Bearer ${config.token}`,
75
- },
76
- body: JSON.stringify(requestBody),
77
- });
78
- const responseText = yield response.text();
79
- console.log('Configuration response status:', response.status);
80
- console.log('Configuration response text:', responseText);
81
- const responseData = JSON.parse(responseText);
82
- if (response.ok) {
83
- console.log('✅ Configuration deployed successfully!');
84
- return responseData.release_id;
85
- }
86
- else {
87
- console.log('❌ Configuration failed!');
88
- console.log('Error:', responseData.error || 'Unknown error');
89
- console.log('Response data:', JSON.stringify(responseData, null, 2));
90
- throw new Error('Configuration upload failed');
91
- }
92
- }
93
- catch (e) {
94
- console.log('error', e);
95
- throw new Error('Error sending configuration');
76
+ else {
77
+ console.log('Configuration failed!');
78
+ console.log('Error:', responseData.error || 'Unknown error');
79
+ console.log('Response data:', JSON.stringify(responseData, null, 2));
80
+ throw new Error('Configuration upload failed');
96
81
  }
97
82
  }
98
- catch (error) {
99
- console.error('❌ Error sending configuration:', error.message);
100
- throw error;
83
+ catch (e) {
84
+ console.log('error', e);
85
+ throw new Error('Error sending configuration');
101
86
  }
102
- });
87
+ }
88
+ catch (error) {
89
+ console.error('❌ Error sending configuration:', error.message);
90
+ throw error;
91
+ }
103
92
  }
104
- export function releasePlugin(config, release_id) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const response = yield fetch(`${config.domain}/release/${release_id}/release`, {
107
- method: 'POST',
108
- headers: {
109
- 'Content-Type': 'application/json',
110
- Authorization: `Bearer ${config.token}`,
111
- },
112
- body: JSON.stringify({ plugin_id: config.plugin_id }),
113
- });
114
- if (!response.ok) {
115
- console.log('Response:', yield response.text());
116
- throw new Error('Failed to release plugin');
117
- }
118
- console.log('✅ Plugin released successfully');
93
+ export async function releasePlugin(config, release_id) {
94
+ const response = await fetch(`${config.domain}/release/${release_id}/release`, {
95
+ method: 'POST',
96
+ headers: {
97
+ 'Content-Type': 'application/json',
98
+ Authorization: `Bearer ${config.token}`,
99
+ },
100
+ body: JSON.stringify({ plugin_id: config.plugin_id }),
119
101
  });
102
+ if (!response.ok) {
103
+ console.log('Response:', await response.text());
104
+ throw new Error('Failed to release plugin');
105
+ }
106
+ console.log('✅ Plugin released successfully');
120
107
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import fs from 'fs';
11
2
  import path from 'path';
12
3
  import ts from 'typescript';
@@ -14,87 +5,85 @@ import ts from 'typescript';
14
5
  * Read and send the database configuration to the release endpoint
15
6
  * @param config - Configuration object
16
7
  */
17
- export default function dbUpdate(config, release_id) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const dbConfigPath = path.resolve('./rimori/db.config.ts');
20
- // Check if db config file exists
8
+ export default async function dbUpdate(config, release_id) {
9
+ const dbConfigPath = path.resolve('./rimori/db.config.ts');
10
+ // Check if db config file exists
11
+ try {
12
+ await fs.promises.access(dbConfigPath);
13
+ }
14
+ catch (e) {
15
+ console.warn('Could not find db.config.ts in ./rimori/ directory. Skipping database configuration upload.');
16
+ return;
17
+ }
18
+ try {
19
+ let dbConfigObject;
20
+ // Use TypeScript compiler to transpile and load
21
+ const dbConfigContent = await fs.promises.readFile(dbConfigPath, 'utf8');
22
+ // Transpile TypeScript to JavaScript
23
+ const result = ts.transpile(dbConfigContent, {
24
+ target: ts.ScriptTarget.ES2020,
25
+ module: ts.ModuleKind.ES2020,
26
+ });
27
+ // Create a temporary file to import the transpiled code
28
+ const tempFile = path.join(process.cwd(), 'temp_db_config.js');
29
+ await fs.promises.writeFile(tempFile, result);
21
30
  try {
22
- yield fs.promises.access(dbConfigPath);
31
+ // Use dynamic import to load the db config
32
+ const dbConfig = await import(`file://${tempFile}`);
33
+ dbConfigObject = Object.values(dbConfig);
34
+ // Clean up temp file
35
+ await fs.promises.unlink(tempFile);
23
36
  }
24
- catch (e) {
25
- console.warn('Could not find db.config.ts in ./rimori/ directory. Skipping database configuration upload.');
26
- return;
27
- }
28
- try {
29
- let dbConfigObject;
30
- // Use TypeScript compiler to transpile and load
31
- const dbConfigContent = yield fs.promises.readFile(dbConfigPath, 'utf8');
32
- // Transpile TypeScript to JavaScript
33
- const result = ts.transpile(dbConfigContent, {
34
- target: ts.ScriptTarget.ES2020,
35
- module: ts.ModuleKind.ES2020,
36
- });
37
- // Create a temporary file to import the transpiled code
38
- const tempFile = path.join(process.cwd(), 'temp_db_config.js');
39
- yield fs.promises.writeFile(tempFile, result);
37
+ catch (error) {
38
+ // Clean up temp file even on error
40
39
  try {
41
- // Use dynamic import to load the db config
42
- const dbConfig = yield import(`file://${tempFile}`);
43
- dbConfigObject = Object.values(dbConfig);
44
- // Clean up temp file
45
- yield fs.promises.unlink(tempFile);
40
+ await fs.promises.unlink(tempFile);
46
41
  }
47
- catch (error) {
48
- // Clean up temp file even on error
49
- try {
50
- yield fs.promises.unlink(tempFile);
51
- }
52
- catch (e) { }
53
- throw error;
54
- }
55
- if (!dbConfigObject) {
56
- throw new Error('Database configuration object is empty or undefined');
57
- }
58
- console.log(`🗄️ Sending database configuration...`);
59
- const requestBody = {
60
- db_config: dbConfigObject,
61
- version: config.version,
62
- release_channel: config.release_channel,
63
- plugin_id: config.plugin_id,
64
- };
65
- const response = yield fetch(`${config.domain}/release/${release_id}/db`, {
66
- method: 'POST',
67
- headers: {
68
- 'Content-Type': 'application/json',
69
- Authorization: `Bearer ${config.token}`,
70
- },
71
- body: JSON.stringify(requestBody),
72
- }).catch((e) => {
42
+ catch (e) { }
43
+ throw error;
44
+ }
45
+ if (!dbConfigObject) {
46
+ throw new Error('Database configuration object is empty or undefined');
47
+ }
48
+ console.log(`🗄️ Sending database configuration...`);
49
+ const requestBody = {
50
+ db_config: dbConfigObject,
51
+ version: config.version,
52
+ release_channel: config.release_channel,
53
+ plugin_id: config.plugin_id,
54
+ };
55
+ const response = await fetch(`${config.domain}/release/${release_id}/db`, {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-Type': 'application/json',
59
+ Authorization: `Bearer ${config.token}`,
60
+ },
61
+ body: JSON.stringify(requestBody),
62
+ }).catch((e) => {
63
+ console.log('error', e);
64
+ throw new Error('Error sending database configuration');
65
+ });
66
+ try {
67
+ const responseText = await response.text().catch((e) => {
73
68
  console.log('error', e);
74
69
  throw new Error('Error sending database configuration');
75
70
  });
76
- try {
77
- const responseText = yield response.text().catch((e) => {
78
- console.log('error', e);
79
- throw new Error('Error sending database configuration');
80
- });
81
- const responseData = JSON.parse(responseText);
82
- if (response.ok) {
83
- console.log('✅ Database configuration deployed successfully!');
84
- }
85
- else {
86
- console.log('responseData', responseData);
87
- throw new Error(responseData.message);
88
- }
71
+ const responseData = JSON.parse(responseText);
72
+ if (response.ok) {
73
+ console.log('✅ Database configuration deployed successfully!');
89
74
  }
90
- catch (e) {
91
- console.log('error', e);
92
- throw new Error('Error sending database configuration');
75
+ else {
76
+ console.log('responseData', responseData);
77
+ throw new Error(responseData.message);
93
78
  }
94
79
  }
95
- catch (error) {
96
- console.error('❌ Error sending database configuration:', error.message);
97
- throw error;
80
+ catch (e) {
81
+ console.log('error', e);
82
+ throw new Error('Error sending database configuration');
98
83
  }
99
- });
84
+ }
85
+ catch (error) {
86
+ console.error('❌ Error sending database configuration:', error.message);
87
+ throw error;
88
+ }
100
89
  }
@@ -1,114 +1,98 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import fs from 'fs';
11
2
  import path from 'path';
12
3
  /**
13
4
  * Upload all files from a directory and its subdirectories to the release function
14
5
  * @param config - Configuration object
15
6
  */
16
- export function uploadDirectory(config, release_id) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const relativePath = './dist';
19
- console.log(`📁 Preparing to upload files from ${relativePath}...`);
20
- // Check if dist directory exists
7
+ export async function uploadDirectory(config, release_id) {
8
+ const relativePath = './dist';
9
+ console.log(`📁 Preparing to upload files from ${relativePath}...`);
10
+ // Check if dist directory exists
11
+ try {
12
+ await fs.promises.access(relativePath);
13
+ }
14
+ catch (e) {
15
+ throw new Error(`Directory ${relativePath} does not exist. Make sure to build your plugin first.`);
16
+ }
17
+ // Get all files recursively
18
+ const files = await getAllFiles(relativePath);
19
+ if (files.length === 0) {
20
+ console.log('⚠️ No files found to upload');
21
+ return;
22
+ }
23
+ console.log(`🚀 Uploading ${files.length} files...`);
24
+ // Create FormData
25
+ const formData = new FormData();
26
+ // Add version and release channel data
27
+ formData.append('version', config.version);
28
+ formData.append('release_channel', config.release_channel);
29
+ formData.append('plugin_id', config.plugin_id);
30
+ // Create path mapping with IDs as keys
31
+ const pathMapping = {};
32
+ for (let i = 0; i < files.length; i++) {
33
+ const filePath = files[i];
21
34
  try {
22
- yield fs.promises.access(relativePath);
23
- }
24
- catch (e) {
25
- throw new Error(`Directory ${relativePath} does not exist. Make sure to build your plugin first.`);
26
- }
27
- // Get all files recursively
28
- const files = yield getAllFiles(relativePath);
29
- if (files.length === 0) {
30
- console.log('⚠️ No files found to upload');
31
- return;
32
- }
33
- console.log(`🚀 Uploading ${files.length} files...`);
34
- // Create FormData
35
- const formData = new FormData();
36
- // Add version and release channel data
37
- formData.append('version', config.version);
38
- formData.append('release_channel', config.release_channel);
39
- formData.append('plugin_id', config.plugin_id);
40
- // Create path mapping with IDs as keys
41
- const pathMapping = {};
42
- for (let i = 0; i < files.length; i++) {
43
- const filePath = files[i];
44
- try {
45
- const fileContent = yield fs.promises.readFile(filePath);
46
- const relativePath = path.relative('./dist', filePath);
47
- const contentType = getContentType(filePath);
48
- // Generate unique ID for this file
49
- const fileId = `file_${i}`;
50
- // Add to path mapping using ID as key
51
- pathMapping[fileId] = relativePath;
52
- // Create a Blob with the file content and content type
53
- const blob = new Blob([new Uint8Array(fileContent)], { type: contentType });
54
- // Add file to FormData with ID_filename format
55
- const fileName = `${fileId}_${path.basename(filePath)}`;
56
- formData.append('files', blob, fileName);
57
- }
58
- catch (error) {
59
- console.error(`❌ Error reading file ${filePath}:`, error.message);
60
- throw error;
61
- }
62
- }
63
- // Add path mapping to FormData
64
- formData.append('path_mapping', JSON.stringify(pathMapping));
65
- // Upload to the release endpoint
66
- const response = yield fetch(`${config.domain}/release/${release_id}/files`, {
67
- method: 'POST',
68
- headers: { Authorization: `Bearer ${config.token}` },
69
- body: formData,
70
- });
71
- if (response.ok) {
72
- console.log('✅ Files uploaded successfully!');
35
+ const fileContent = await fs.promises.readFile(filePath);
36
+ const relativePath = path.relative('./dist', filePath);
37
+ const contentType = getContentType(filePath);
38
+ // Generate unique ID for this file
39
+ const fileId = `file_${i}`;
40
+ // Add to path mapping using ID as key
41
+ pathMapping[fileId] = relativePath;
42
+ // Create a Blob with the file content and content type
43
+ const blob = new Blob([new Uint8Array(fileContent)], { type: contentType });
44
+ // Add file to FormData with ID_filename format
45
+ const fileName = `${fileId}_${path.basename(filePath)}`;
46
+ formData.append('files', blob, fileName);
73
47
  }
74
- else {
75
- const errorText = yield response.text();
76
- console.log('❌ File upload failed!');
77
- console.log('Response:', errorText);
78
- throw new Error(`File upload failed with status ${response.status}`);
48
+ catch (error) {
49
+ console.error(`❌ Error reading file ${filePath}:`, error.message);
50
+ throw error;
79
51
  }
52
+ }
53
+ // Add path mapping to FormData
54
+ formData.append('path_mapping', JSON.stringify(pathMapping));
55
+ // Upload to the release endpoint
56
+ const response = await fetch(`${config.domain}/release/${release_id}/files`, {
57
+ method: 'POST',
58
+ headers: { Authorization: `Bearer ${config.token}` },
59
+ body: formData,
80
60
  });
61
+ if (response.ok) {
62
+ console.log('✅ Files uploaded successfully!');
63
+ }
64
+ else {
65
+ const errorText = await response.text();
66
+ console.log('❌ File upload failed!');
67
+ console.log('Response:', errorText);
68
+ throw new Error(`File upload failed with status ${response.status}`);
69
+ }
81
70
  }
82
71
  /**
83
72
  * Recursively get all files from a directory
84
73
  */
85
- function getAllFiles(dirPath) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- const files = [];
88
- function traverse(currentPath) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const entries = yield fs.promises.readdir(currentPath, { withFileTypes: true });
91
- for (const entry of entries) {
92
- const fullPath = path.join(currentPath, entry.name);
93
- if (entry.isDirectory()) {
94
- yield traverse(fullPath);
95
- }
96
- else if (entry.isFile()) {
97
- files.push(fullPath);
98
- }
99
- }
100
- });
74
+ async function getAllFiles(dirPath) {
75
+ const files = [];
76
+ async function traverse(currentPath) {
77
+ const entries = await fs.promises.readdir(currentPath, { withFileTypes: true });
78
+ for (const entry of entries) {
79
+ const fullPath = path.join(currentPath, entry.name);
80
+ if (entry.isDirectory()) {
81
+ await traverse(fullPath);
82
+ }
83
+ else if (entry.isFile()) {
84
+ files.push(fullPath);
85
+ }
101
86
  }
102
- yield traverse(dirPath);
103
- return files;
104
- });
87
+ }
88
+ await traverse(dirPath);
89
+ return files;
105
90
  }
106
91
  /**
107
92
  * Get content type based on file extension
108
93
  */
109
94
  function getContentType(filePath) {
110
- var _a;
111
- const ext = (_a = filePath.split('.').pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
95
+ const ext = filePath.split('.').pop()?.toLowerCase();
112
96
  const contentTypes = {
113
97
  html: 'text/html',
114
98
  css: 'text/css',