From 41a62326bf6502f0ca0cdc884ccc9ed3f109619c Mon Sep 17 00:00:00 2001 From: jelveh Date: Wed, 6 Aug 2025 19:41:14 -0700 Subject: [PATCH] Improve Apps class to enforce required fields and improve title handling. Added validation for name and index URL, as they are mandatory for app creation. Updated title assignment to default to name if not provided. --- src/puter-js/src/modules/Apps.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/puter-js/src/modules/Apps.js b/src/puter-js/src/modules/Apps.js index ccc943eb..212c8b93 100644 --- a/src/puter-js/src/modules/Apps.js +++ b/src/puter-js/src/modules/Apps.js @@ -69,11 +69,14 @@ class Apps{ // * allows for: puter.apps.new({name: 'example-app', indexURL: 'https://example.com'}) * else if (typeof args[0] === 'object' && args[0] !== null) { let options_raw = args[0]; + options = { object: { name: options_raw.name, index_url: options_raw.indexURL, - title: options_raw.title, + // title is optional only if name is provided. + // If title is provided, use it. If not, use name. + title: options_raw.title ?? options_raw.name, description: options_raw.description, icon: options_raw.icon, maximize_on_start: options_raw.maximizeOnStart, @@ -86,6 +89,27 @@ class Apps{ } }; } + + // name and indexURL are required + if(!options.object.name){ + throw { + success: false, + error: { + code: 'invalid_request', + message: 'Name is required' + } + }; + } + if(!options.object.index_url){ + throw { + success: false, + error: { + code: 'invalid_request', + message: 'Index URL is required' + } + }; + } + // Call the original chat.complete method return await utils.make_driver_method(['object'], 'puter-apps', undefined, 'create').call(this, options); }