From 0b7474340f78748b8a361e1e520c947c7b9a175c Mon Sep 17 00:00:00 2001 From: XiaochenCui Date: Fri, 27 Jun 2025 16:19:25 -0700 Subject: [PATCH] dev: extension prefix update, doc helper & docs update --- doc/contributors/extensions/events.json.js | 1584 +++++++++----------- doc/contributors/extensions/events.md | 603 ++++---- mods/mods_available/testex.js | 78 +- src/backend/src/ExtensionService.js | 8 +- tools/doc_helper.js | 23 +- 5 files changed, 1134 insertions(+), 1162 deletions(-) diff --git a/doc/contributors/extensions/events.json.js b/doc/contributors/extensions/events.json.js index 7edd7958c..d5525c8ee 100644 --- a/doc/contributors/extensions/events.json.js +++ b/doc/contributors/extensions/events.json.js @@ -1,952 +1,840 @@ export default [ - { - id: "core.ai.prompt.check-usage", - description: ` - This event is emitted when checking if an AI prompt operation should be allowed. - Extensions can use this event to implement custom usage limits or restrictions. + { + id: 'ai.prompt.check-usage', + description: ` + This event is emitted for ai prompt check usage operations. `, - properties: { - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the operation is allowed", - notes: [], - }, - intended_service: { - type: "any", - mutability: "mutable", - summary: "intended service", - notes: [], - }, - parameters: { - type: "any", - mutability: "mutable", - summary: "parameters", - notes: [], - }, + properties: { + completionId: { + type: 'any', + mutability: 'mutable', + summary: 'completionId', + notes: [], + }, + allow: { + type: 'boolean', + mutability: 'mutable', + summary: 'whether the operation is allowed', + notes: [], + }, + intended_service: { + type: 'any', + mutability: 'mutable', + summary: 'intended service', + notes: [], + }, + parameters: { + type: 'any', + mutability: 'mutable', + summary: 'parameters', + notes: [], + } + }, }, - }, - { - id: "core.ai.prompt.complete", - description: ` + { + id: 'ai.prompt.complete', + description: ` This event is emitted for ai prompt complete operations. `, - properties: { - username: { - type: "string", - mutability: "mutable", - summary: "username", - notes: [], - }, - intended_service: { - type: "any", - mutability: "mutable", - summary: "intended service", - notes: [], - }, - parameters: { - type: "any", - mutability: "mutable", - summary: "parameters", - notes: [], - }, - result: { - type: "any", - mutability: "mutable", - summary: "result", - notes: [], - }, - model_used: { - type: "any", - mutability: "mutable", - summary: "model used", - notes: [], - }, - service_used: { - type: "any", - mutability: "mutable", - summary: "service used", - notes: [], - }, + properties: { + intended_service: { + type: 'any', + mutability: 'mutable', + summary: 'intended service', + notes: [], + }, + parameters: { + type: 'any', + mutability: 'mutable', + summary: 'parameters', + notes: [], + }, + result: { + type: 'any', + mutability: 'mutable', + summary: 'result', + notes: [], + }, + model_used: { + type: 'any', + mutability: 'mutable', + summary: 'model used', + notes: [], + }, + service_used: { + type: 'any', + mutability: 'mutable', + summary: 'service used', + notes: [], + } + }, }, - }, - { - id: "core.ai.prompt.report-usage", - description: ` + { + id: 'ai.prompt.cost-calculated', + description: ` + This event is emitted for ai prompt cost calculated operations. + `, + }, + { + id: 'ai.prompt.report-usage', + description: ` This event is emitted for ai prompt report usage operations. `, - }, - { - id: "core.ai.prompt.validate", - description: ` + }, + { + id: 'ai.prompt.validate', + description: ` This event is emitted when a validate is being validated. The event can be used to block certain validates from being validated. `, - properties: { - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the operation is allowed", - notes: ["If set to false, the ai will be considered invalid."], - }, - intended_service: { - type: "any", - mutability: "mutable", - summary: "intended service", - notes: [], - }, - parameters: { - type: "any", - mutability: "mutable", - summary: "parameters", - notes: [], - }, + properties: { + completionId: { + type: 'any', + mutability: 'mutable', + summary: 'completionId', + notes: [], + }, + allow: { + type: 'boolean', + mutability: 'mutable', + summary: 'whether the operation is allowed', + notes: [ + 'If set to false, the ai will be considered invalid.', + ], + }, + intended_service: { + type: 'any', + mutability: 'mutable', + summary: 'intended service', + notes: [], + }, + parameters: { + type: 'any', + mutability: 'mutable', + summary: 'parameters', + notes: [], + } + }, }, - }, - { - id: "core.app.new-icon", - description: ` + { + id: 'app.new-icon', + description: ` This event is emitted for app new icon operations. `, - properties: { - app_uid: { - type: "string", - mutability: "no-effect", - summary: "app uid", - notes: [], - }, - data_url: { - type: "any", - mutability: "no-effect", - summary: "data url", - notes: [], - }, + properties: { + data_url: { + type: 'any', + mutability: 'no-effect', + summary: 'data url', + notes: [], + } + }, }, - }, - { - id: "core.app.rename", - description: ` + { + id: 'app.rename', + description: ` This event is emitted for app rename operations. `, - properties: { - app_uid: { - type: "string", - mutability: "no-effect", - summary: "app uid", - notes: [], - }, - data_url: { - type: "any", - mutability: "no-effect", - summary: "data url", - notes: [], - }, + properties: { + data_url: { + type: 'any', + mutability: 'no-effect', + summary: 'data url', + notes: [], + } + }, }, - }, - { - id: "core.apps.invalidate", - description: ` - This event is emitted when the app cache needs to be invalidated. - This typically happens when apps are installed, updated, or removed. + { + id: 'apps.invalidate', + description: ` + This event is emitted when a invalidate is being validated. + The event can be used to block certain invalidates from being validated. `, - properties: { - options: { - type: "any", - mutability: "no-effect", - summary: "options", - notes: [], - }, - apps: { - type: "any", - mutability: "no-effect", - summary: "apps", - notes: [], - }, + properties: { + apps: { + type: 'any', + mutability: 'no-effect', + summary: 'apps', + notes: [], + } + }, }, - }, - { - id: "core.email.validate", - description: ` + { + id: 'captcha.check', + description: ` + This event is emitted for captcha check operations. + `, + properties: { + required: { + type: 'any', + mutability: 'no-effect', + summary: 'required', + notes: [], + } + }, + }, + { + id: 'core.email.validate', + description: ` This event is emitted when an email is being validated. The event can be used to block certain emails from being validated. `, - properties: { - email: { - type: "string", - mutability: "no-effect", - summary: "the email being validated", - notes: ["The email may have already been cleaned."], - }, - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the email is allowed", - notes: ["If set to false, the email will be considered invalid."], - }, + properties: { + email: { + type: 'string', + mutability: 'no-effect', + summary: 'the email being validated', + notes: [ + 'The email may have already been cleaned.' + ] + }, + allow: { + type: 'boolean', + mutability: 'mutable', + summary: 'whether the email is allowed', + notes: [ + 'If set to false, the email will be considered invalid.' + ] + } + }, }, - }, - { - id: "core.fs.create.directory", - description: ` + { + id: 'core.fs.create.directory', + description: ` This event is emitted when a directory is created. `, - properties: { - node: { - type: "FSNodeContext", - mutability: "no-effect", - summary: "the directory that was created", - }, - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - }, + properties: { + node: { + type: 'FSNodeContext', + mutability: 'no-effect', + summary: 'the directory that was created' + }, + context: { + type: 'Context', + mutability: 'no-effect', + summary: 'current context' + } + }, }, - }, - { - id: "core.fs.create.file", - description: ` + { + id: 'core.request.measured', + description: ` + This event is emitted when a requests incoming and outgoing bytes + have been measured. + `, + example: { + language: 'javascript', + code: /*javascript*/` + extension.on('core.request.measured', data => { + const measurements = data.measurements; + // measurements = { sz_incoming: integer, sz_outgoing: integer } + + const actor = data.actor; // instance of Actor + + console.log('\x1B[36;1m === MEASUREMENT ===\x1B[0m\n', { + actor: data.actor.uid, + measurements: data.measurements + }); + }); + ` + }, + }, + { + id: 'credit.check-available', + description: ` + This event is emitted for credit check available operations. + `, + properties: { + available: { + type: 'any', + mutability: 'no-effect', + summary: 'available', + notes: [], + }, + cost_uuid: { + type: 'string', + mutability: 'no-effect', + summary: 'cost uuid', + notes: [], + } + }, + }, + { + id: 'credit.funding-update', + description: ` + This event is emitted when a funding-update is updated. + `, + properties: { + available: { + type: 'any', + mutability: 'no-effect', + summary: 'available', + notes: [], + }, + cost_uuid: { + type: 'string', + mutability: 'no-effect', + summary: 'cost uuid', + notes: [], + } + }, + }, + { + id: 'credit.record-cost', + description: ` + This event is emitted for credit record cost operations. + `, + properties: { + available: { + type: 'any', + mutability: 'no-effect', + summary: 'available', + notes: [], + }, + cost_uuid: { + type: 'string', + mutability: 'no-effect', + summary: 'cost uuid', + notes: [], + } + }, + }, + { + id: 'driver.create-call-context', + description: ` + This event is emitted when a create-call-context is created. + `, + properties: { + usages: { + type: 'any', + mutability: 'no-effect', + summary: 'usages', + notes: [], + } + }, + }, + { + id: 'email.validate', + description: ` + This event is emitted when a validate is being validated. + The event can be used to block certain validates from being validated. + `, + properties: { + allow: { + type: 'boolean', + mutability: 'mutable', + summary: 'whether the operation is allowed', + notes: [ + 'If set to false, the email will be considered invalid.', + ], + }, + email: { + type: 'any', + mutability: 'mutable', + summary: 'email', + notes: [ + 'The email may have already been cleaned.', + ], + } + }, + }, + { + id: 'fs.create.directory', + description: ` + This event is emitted when a directory is created. + `, + }, + { + id: 'fs.create.file', + description: ` This event is emitted when a file is created. `, - properties: { - node: { - type: "FSNodeContext", - mutability: "no-effect", - summary: "the file that was affected", - notes: [], - }, - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - notes: [], - }, + properties: { + context: { + type: 'Context', + mutability: 'no-effect', + summary: 'current context', + notes: [], + } + }, }, - }, - { - id: "core.fs.create.shortcut", - description: ` + { + id: 'fs.create.shortcut', + description: ` This event is emitted when a shortcut is created. `, - }, - { - id: "core.fs.create.symlink", - description: ` + }, + { + id: 'fs.create.symlink', + description: ` This event is emitted when a symlink is created. `, - }, - { - id: "core.fs.move.file", - description: ` + }, + { + id: 'fs.move.file', + description: ` This event is emitted for fs move file operations. `, - properties: { - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - notes: [], - }, - moved: { - type: "any", - mutability: "no-effect", - summary: "moved", - notes: [], - }, - old_path: { - type: "string", - mutability: "no-effect", - summary: "path to the affected resource", - notes: [], - }, + properties: { + moved: { + type: 'any', + mutability: 'no-effect', + summary: 'moved', + notes: [], + }, + old_path: { + type: 'string', + mutability: 'no-effect', + summary: 'path to the affected resource', + notes: [], + } + }, }, - }, - { - id: "core.fs.pending.file", - description: ` + { + id: 'fs.pending.file', + description: ` This event is emitted for fs pending file operations. `, - }, - { - id: "core.fs.storage.progress.copy", - description: ` - This event reports progress during a file copy operation. - It provides detailed information about the progress of large file transfers. - `, - properties: { - upload_tracker: { - type: "ProgressTracker", - mutability: "no-effect", - summary: "tracks progress of the operation", - notes: [], - }, - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - notes: [], - }, - meta: { - type: "object", - mutability: "no-effect", - summary: "additional metadata for the operation", - notes: [], - }, - item_path: { - type: "string", - mutability: "no-effect", - summary: "path to the affected resource", - notes: [], - }, }, - }, - { - id: "core.fs.storage.upload-progress", - description: ` - This event reports progress during a file upload operation. - It provides real-time updates about the progress of file uploads. + { + id: 'fs.storage.progress.copy', + description: ` + This event reports progress of a copy operation. `, - properties: { - progress: { - type: "number", - mutability: "no-effect", - summary: "upload progress percentage (0-100)", - notes: [], - }, - bytes_uploaded: { - type: "number", - mutability: "no-effect", - summary: "number of bytes uploaded so far", - notes: [], - }, - total_bytes: { - type: "number", - mutability: "no-effect", - summary: "total number of bytes to upload", - notes: [], - }, + properties: { + context: { + type: 'Context', + mutability: 'no-effect', + summary: 'current context', + notes: [], + }, + meta: { + type: 'object', + mutability: 'no-effect', + summary: 'additional metadata for the operation', + notes: [], + }, + item_path: { + type: 'string', + mutability: 'no-effect', + summary: 'path to the affected resource', + notes: [], + } + }, }, - }, - { - id: "core.fs.write.file", - description: ` + { + id: 'fs.storage.upload-progress', + description: ` + This event reports progress of a upload-progress operation. + `, + }, + { + id: 'fs.write.file', + description: ` This event is emitted when a file is updated. `, - properties: { - node: { - type: "FSNodeContext", - mutability: "no-effect", - summary: "the file that was affected", - notes: [], - }, - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - notes: [], - }, + properties: { + context: { + type: 'Context', + mutability: 'no-effect', + summary: 'current context', + notes: [], + } + }, }, - }, - { - id: "core.ip.validate", - description: ` - This event is emitted when validating an IP address. - Extensions can use this event to implement IP-based access control. + { + id: 'ip.validate', + description: ` + This event is emitted when a validate is being validated. + The event can be used to block certain validates from being validated. `, - properties: { - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the IP address is allowed", - notes: ["If set to false, access from this IP will be blocked"], - }, - ip: { - type: "string", - mutability: "no-effect", - summary: "the IP address being validated", - notes: [], - }, + properties: { + res: { + type: 'any', + mutability: 'mutable', + summary: 'res', + notes: [], + }, + end_: { + type: 'any', + mutability: 'mutable', + summary: 'end ', + notes: [], + }, + end: { + type: 'any', + mutability: 'mutable', + summary: 'end', + notes: [], + } + }, }, - }, - { - id: "core.outer.fs.write-hash", - description: ` + { + id: 'outer.fs.write-hash', + description: ` This event is emitted when a write-hash is updated. `, - properties: { - hash: { - type: "any", - mutability: "no-effect", - summary: "hash", - notes: [], - }, - uuid: { - type: "string", - mutability: "no-effect", - summary: "uuid", - notes: [], - }, + properties: { + uuid: { + type: 'string', + mutability: 'no-effect', + summary: 'uuid', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.item.added", - description: ` + { + id: 'outer.gui.item.added', + description: ` This event is emitted for outer gui item added operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.item.moved", - description: ` + { + id: 'outer.gui.item.moved', + description: ` This event is emitted for outer gui item moved operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.item.pending", - description: ` + { + id: 'outer.gui.item.pending', + description: ` This event is emitted for outer gui item pending operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.item.updated", - description: ` + { + id: 'outer.gui.item.updated', + description: ` This event is emitted when a updated is updated. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.notif.ack", - description: ` + { + id: 'outer.gui.notif.ack', + description: ` This event is emitted for outer gui notif ack operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.notif.message", - description: ` + { + id: 'outer.gui.notif.message', + description: ` This event is emitted for outer gui notif message operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, - notification: { - type: "any", - mutability: "no-effect", - summary: "notification", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + }, + notification: { + type: 'any', + mutability: 'no-effect', + summary: 'notification', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.notif.persisted", - description: ` + { + id: 'outer.gui.notif.persisted', + description: ` This event is emitted for outer gui notif persisted operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.notif.unreads", - description: ` + { + id: 'outer.gui.notif.unreads', + description: ` This event is emitted for outer gui notif unreads operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.outer.gui.submission.done", - description: ` + { + id: 'outer.gui.submission.done', + description: ` This event is emitted for outer gui submission done operations. `, - properties: { - user_id_list: { - type: "string", - mutability: "no-effect", - summary: "user id list", - notes: [], - }, - response: { - type: "any", - mutability: "no-effect", - summary: "response", - notes: [], - }, + properties: { + response: { + type: 'any', + mutability: 'no-effect', + summary: 'response', + notes: [], + } + }, }, - }, - { - id: "core.puter-exec.submission.done", - description: ` - This event is emitted for puter-exec submission done operations. + { + id: 'outer.gui.usage.update', + description: ` + This event is emitted when a update is updated. `, - }, - { - id: "core.request.measured", - description: ` - This event is emitted when a request has been measured for performance metrics. - `, - properties: { - duration: { - type: "number", - mutability: "no-effect", - summary: "request duration in milliseconds", - notes: [], - }, - path: { - type: "string", - mutability: "no-effect", - summary: "request path", - notes: [], - }, }, - }, - { - id: "core.sns", - description: ` + { + id: 'outer.thread.notify-subscribers', + description: ` + This event is emitted for outer thread notify subscribers operations. + `, + properties: { + uid: { + type: 'string', + mutability: 'no-effect', + summary: 'uid', + notes: [], + }, + action: { + type: 'any', + mutability: 'no-effect', + summary: 'action', + notes: [], + }, + data: { + type: 'any', + mutability: 'no-effect', + summary: 'data', + notes: [], + } + }, + }, + { + id: 'puter.signup', + description: ` + This event is emitted for puter signup operations. + `, + properties: { + ip: { + type: 'any', + mutability: 'mutable', + summary: 'ip', + notes: [], + }, + user_agent: { + type: 'any', + mutability: 'mutable', + summary: 'user agent', + notes: [], + }, + body: { + type: 'any', + mutability: 'mutable', + summary: 'body', + notes: [], + } + }, + }, + { + id: 'request.measured', + description: ` + This event is emitted for request measured operations. + `, + properties: { + req: { + type: 'any', + mutability: 'no-effect', + summary: 'req', + notes: [], + }, + res: { + type: 'any', + mutability: 'no-effect', + summary: 'res', + notes: [], + } + }, + }, + { + id: 'request.will-be-handled', + description: ` + This event is emitted for request will be handled operations. + `, + properties: { + res: { + type: 'any', + mutability: 'mutable', + summary: 'res', + notes: [], + }, + end_: { + type: 'any', + mutability: 'mutable', + summary: 'end ', + notes: [], + }, + end: { + type: 'any', + mutability: 'mutable', + summary: 'end', + notes: [], + } + }, + }, + { + id: 'sns', + description: ` This event is emitted for sns operations. `, - properties: { - message: { - type: "any", - mutability: "no-effect", - summary: "message", - notes: [], - }, + properties: { + message: { + type: 'any', + mutability: 'no-effect', + summary: 'message', + notes: [], + } + }, }, - }, - { - id: "core.template-service.hello", - description: ` + { + id: 'template-service.hello', + description: ` This event is emitted for template-service hello operations. `, - properties: { - message: { - type: "any", - mutability: "no-effect", - summary: "message", - notes: [], - }, }, - }, - { - id: "core.usages.query", - description: ` + { + id: 'usages.query', + description: ` This event is emitted for usages query operations. `, - properties: { - actor: { - type: "any", - mutability: "no-effect", - summary: "actor", - notes: [], - }, - usages: { - type: "any", - mutability: "no-effect", - summary: "usages", - notes: [], - }, + properties: { + usages: { + type: 'any', + mutability: 'no-effect', + summary: 'usages', + notes: [], + } + }, }, - }, - { - id: "core.user.email-changed", - description: ` - This event is emitted when a user changes their email address. + { + id: 'user.email-changed', + description: ` + This event is emitted for user email changed operations. `, - properties: { - user: { - type: "object", - mutability: "no-effect", - summary: "user object", - notes: [], - }, - old_email: { - type: "string", - mutability: "no-effect", - summary: "previous email address", - notes: [], - }, - new_email: { - type: "string", - mutability: "no-effect", - summary: "new email address", - notes: [], - }, + properties: { + new_email: { + type: 'any', + mutability: 'no-effect', + summary: 'new email', + notes: [], + } + }, }, - }, - { - id: "core.user.email-confirmed", - description: ` + { + id: 'user.email-confirmed', + description: ` This event is emitted for user email confirmed operations. `, - properties: { - user_uid: { - type: "string", - mutability: "no-effect", - summary: "user uid", - notes: [], - }, - email: { - type: "any", - mutability: "no-effect", - summary: "email", - notes: [], - }, + properties: { + email: { + type: 'any', + mutability: 'no-effect', + summary: 'email', + notes: [], + } + }, }, - }, - { - id: "core.user.save_account", - description: ` - This event is emitted when a user's account details are saved. + { + id: 'user.save_account', + description: ` + This event is emitted for user save_account operations. `, - properties: { - user: { - type: "object", - mutability: "no-effect", - summary: "user object with updated details", - notes: [], - }, + properties: { + user: { + type: 'User', + mutability: 'no-effect', + summary: 'user associated with the operation', + notes: [], + } + }, }, - }, - { - id: "core.web.socket.connected", - description: ` + { + id: 'web.socket.connected', + description: ` This event is emitted for web socket connected operations. `, - properties: { - socket: { - type: "any", - mutability: "mutable", - summary: "socket", - notes: [], - }, - user: { - type: "User", - mutability: "mutable", - summary: "user associated with the operation", - notes: [], - }, + properties: { + user: { + type: 'User', + mutability: 'mutable', + summary: 'user associated with the operation', + notes: [], + } + }, }, - }, - { - id: "core.web.socket.user-connected", - description: ` + { + id: 'web.socket.user-connected', + description: ` This event is emitted for web socket user connected operations. `, - properties: { - socket: { - type: "any", - mutability: "mutable", - summary: "socket", - notes: [], - }, - user: { - type: "User", - mutability: "mutable", - summary: "user associated with the operation", - notes: [], - }, + properties: { + user: { + type: 'User', + mutability: 'mutable', + summary: 'user associated with the operation', + notes: [], + } + }, }, - }, - { - id: "core.wisp.get-policy", - description: ` + { + id: 'wisp.get-policy', + description: ` This event is emitted for wisp get policy operations. `, - properties: { - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the operation is allowed", - notes: [], - }, - policy: { - type: "Policy", - mutability: "mutable", - summary: "policy information for the operation", - notes: [], - }, - }, - }, - { - id: "core.credit.check-available", - description: ` - This event is emitted when checking if a user has enough credits available for an operation. - `, - properties: { - amount: { - type: "number", - mutability: "no-effect", - summary: "the amount of credits to check", - notes: [], - }, - user: { - type: "object", - mutability: "no-effect", - summary: "user object", - notes: [], - }, - }, - }, - { - id: "core.credit.record-cost", - description: ` - This event is emitted when recording a cost against a user's credits. - `, - properties: { - amount: { - type: "number", - mutability: "no-effect", - summary: "the amount of credits to deduct", - notes: [], - }, - user: { - type: "object", - mutability: "no-effect", - summary: "user object", - notes: [], - }, - }, - }, - { - id: "core.credit.funding-update", - description: ` - This event is emitted when a user's credit balance is updated. - `, - properties: { - user: { - type: "object", - mutability: "no-effect", - summary: "user object", - notes: [], - }, - balance: { - type: "number", - mutability: "no-effect", - summary: "new balance", - notes: [], - }, - }, - }, - { - id: "core.driver.create-call-context", - description: ` - This event is emitted when a driver call context is being created. - `, - properties: { - context: { - type: "Context", - mutability: "no-effect", - summary: "current context", - notes: [], - }, - }, - }, - { - id: "core.thread.notify-subscribers", - description: ` - This event is emitted when thread subscribers need to be notified of changes. - `, - properties: { - uid: { - type: "string", - mutability: "no-effect", - summary: "thread unique identifier", - notes: [], - }, - action: { - type: "string", - mutability: "no-effect", - summary: "action that occurred", - notes: [], - }, - data: { - type: "any", - mutability: "no-effect", - summary: "data associated with the action", - notes: [], - }, - }, - }, - { - id: "core.request.will-be-handled", - description: ` - This event is emitted just before a request is handled by the web server. - It allows extensions to perform pre-request processing. - `, - properties: { - request: { - type: "object", - mutability: "no-effect", - summary: "the HTTP request object", - notes: [], - }, - response: { - type: "object", - mutability: "no-effect", - summary: "the HTTP response object", - notes: [], - }, - }, - }, - { - id: "core.puter.signup", - description: ` - This event is emitted when a new user signs up. - `, - properties: { - user: { - type: "object", - mutability: "no-effect", - summary: "the newly created user object", - notes: [], - }, - email: { - type: "string", - mutability: "no-effect", - summary: "email address of the new user", - notes: [], - }, - }, - }, - { - id: "core.captcha.check", - description: ` - This event is emitted when a CAPTCHA verification needs to be performed. - `, - properties: { - token: { - type: "string", - mutability: "no-effect", - summary: "CAPTCHA token to verify", - notes: [], - }, - allow: { - type: "boolean", - mutability: "mutable", - summary: "whether the CAPTCHA verification passed", - notes: ["If set to false, the request will be rejected"], - }, - }, - }, - { - id: "core.outer.gui.usage.update", - description: ` - This event is emitted when a user's usage statistics need to be updated. - `, - properties: { - user_id: { - type: "string", - mutability: "no-effect", - summary: "ID of the user whose usage is being updated", - notes: [], - }, - usage: { - type: "object", - mutability: "no-effect", - summary: "updated usage statistics", - notes: [], - }, - }, - }, + properties: { + policy: { + type: 'Policy', + mutability: 'mutable', + summary: 'policy information for the operation', + notes: [], + } + }, + } ]; diff --git a/doc/contributors/extensions/events.md b/doc/contributors/extensions/events.md index a158fee35..14f84e2e8 100644 --- a/doc/contributors/extensions/events.md +++ b/doc/contributors/extensions/events.md @@ -1,65 +1,14 @@ -### `core.email.validate` - -This event is emitted when an email is being validated. -The event can be used to block certain emails from being validated. - -#### Property `email` - -the email being validated -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - - The email may have already been cleaned. - -#### Property `allow` - -whether the email is allowed -- **Type**: boolean -- **Mutability**: mutable -- **Notes**: - - If set to false, the email will be considered invalid. - -### `core.request.measured` - -This event is emitted when a requests incoming and outgoing bytes -have been measured. - -#### Example - -```javascript -extension.on('core.request.measured', data => { - const measurements = data.measurements; - // measurements = { sz_incoming: integer, sz_outgoing: integer } - - const actor = data.actor; // instance of Actor - - console.log('\x1B[36;1m === MEASUREMENT ===\x1B[0m\n', { - actor: data.actor.uid, - measurements: data.measurements - }); -}); -``` - -### `core.fs.create.directory` - -This event is emitted when a directory is created. - -#### Property `node` - -the directory that was created -- **Type**: FSNodeContext -- **Mutability**: no-effect - -#### Property `context` - -current context -- **Type**: Context -- **Mutability**: no-effect - -### `core.ai.prompt.check-usage` +### `ai.prompt.check-usage` This event is emitted for ai prompt check usage operations. +#### Property `completionId` + +completionId +- **Type**: any +- **Mutability**: mutable +- **Notes**: + #### Property `allow` whether the operation is allowed @@ -81,17 +30,11 @@ parameters - **Mutability**: mutable - **Notes**: -### `core.ai.prompt.complete` + +### `ai.prompt.complete` This event is emitted for ai prompt complete operations. -#### Property `username` - -username -- **Type**: string -- **Mutability**: mutable -- **Notes**: - #### Property `intended_service` intended service @@ -128,16 +71,28 @@ service used - **Notes**: -### `core.ai.prompt.report-usage` +### `ai.prompt.cost-calculated` + +This event is emitted for ai prompt cost calculated operations. + + +### `ai.prompt.report-usage` This event is emitted for ai prompt report usage operations. -### `core.ai.prompt.validate` +### `ai.prompt.validate` This event is emitted when a validate is being validated. The event can be used to block certain validates from being validated. +#### Property `completionId` + +completionId +- **Type**: any +- **Mutability**: mutable +- **Notes**: + #### Property `allow` whether the operation is allowed @@ -161,17 +116,10 @@ parameters - **Notes**: -### `core.app.new-icon` +### `app.new-icon` This event is emitted for app new icon operations. -#### Property `app_uid` - -app uid -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `data_url` data url @@ -180,17 +128,10 @@ data url - **Notes**: -### `core.app.rename` +### `app.rename` This event is emitted for app rename operations. -#### Property `app_uid` - -app uid -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `data_url` data url @@ -199,18 +140,11 @@ data url - **Notes**: -### `core.apps.invalidate` +### `apps.invalidate` This event is emitted when a invalidate is being validated. The event can be used to block certain invalidates from being validated. -#### Property `options` - -options -- **Type**: any -- **Mutability**: no-effect -- **Notes**: - #### Property `apps` apps @@ -218,17 +152,180 @@ apps - **Mutability**: no-effect - **Notes**: -### `core.fs.create.file` -This event is emitted when a file is created. +### `captcha.check` + +This event is emitted for captcha check operations. + +#### Property `required` + +required +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + + +### `core.email.validate` + +This event is emitted when an email is being validated. +The event can be used to block certain emails from being validated. + +#### Property `email` + +the email being validated +- **Type**: string +- **Mutability**: no-effect +- **Notes**: + - The email may have already been cleaned. + +#### Property `allow` + +whether the email is allowed +- **Type**: boolean +- **Mutability**: mutable +- **Notes**: + - If set to false, the email will be considered invalid. + + +### `core.fs.create.directory` + +This event is emitted when a directory is created. #### Property `node` -the file that was affected +the directory that was created - **Type**: FSNodeContext - **Mutability**: no-effect + +#### Property `context` + +current context +- **Type**: Context +- **Mutability**: no-effect + + +### `core.request.measured` + +This event is emitted when a requests incoming and outgoing bytes +have been measured. + +#### Example + +```javascript +extension.on('core.request.measured', data => { + const measurements = data.measurements; + // measurements = { sz_incoming: integer, sz_outgoing: integer } + + const actor = data.actor; // instance of Actor + + console.log(' === MEASUREMENT === +', { + actor: data.actor.uid, + measurements: data.measurements + }); +}); +``` + +### `credit.check-available` + +This event is emitted for credit check available operations. + +#### Property `available` + +available +- **Type**: any +- **Mutability**: no-effect - **Notes**: +#### Property `cost_uuid` + +cost uuid +- **Type**: string +- **Mutability**: no-effect +- **Notes**: + + +### `credit.funding-update` + +This event is emitted when a funding-update is updated. + +#### Property `available` + +available +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + +#### Property `cost_uuid` + +cost uuid +- **Type**: string +- **Mutability**: no-effect +- **Notes**: + + +### `credit.record-cost` + +This event is emitted for credit record cost operations. + +#### Property `available` + +available +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + +#### Property `cost_uuid` + +cost uuid +- **Type**: string +- **Mutability**: no-effect +- **Notes**: + + +### `driver.create-call-context` + +This event is emitted when a create-call-context is created. + +#### Property `usages` + +usages +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + + +### `email.validate` + +This event is emitted when a validate is being validated. +The event can be used to block certain validates from being validated. + +#### Property `allow` + +whether the operation is allowed +- **Type**: boolean +- **Mutability**: mutable +- **Notes**: + - If set to false, the email will be considered invalid. + +#### Property `email` + +email +- **Type**: any +- **Mutability**: mutable +- **Notes**: + - The email may have already been cleaned. + + +### `fs.create.directory` + +This event is emitted when a directory is created. + + +### `fs.create.file` + +This event is emitted when a file is created. + #### Property `context` current context @@ -237,27 +334,20 @@ current context - **Notes**: -### `core.fs.create.shortcut` +### `fs.create.shortcut` This event is emitted when a shortcut is created. -### `core.fs.create.symlink` +### `fs.create.symlink` This event is emitted when a symlink is created. -### `core.fs.move.file` +### `fs.move.file` This event is emitted for fs move file operations. -#### Property `context` - -current context -- **Type**: Context -- **Mutability**: no-effect -- **Notes**: - #### Property `moved` moved @@ -273,22 +363,15 @@ path to the affected resource - **Notes**: -### `core.fs.pending.file` +### `fs.pending.file` This event is emitted for fs pending file operations. -### `core.fs.storage.progress.copy` +### `fs.storage.progress.copy` This event reports progress of a copy operation. -#### Property `upload_tracker` - -tracks progress of the operation -- **Type**: ProgressTracker -- **Mutability**: no-effect -- **Notes**: - #### Property `context` current context @@ -311,22 +394,15 @@ path to the affected resource - **Notes**: -### `core.fs.storage.upload-progress` +### `fs.storage.upload-progress` This event reports progress of a upload-progress operation. -### `core.fs.write.file` +### `fs.write.file` This event is emitted when a file is updated. -#### Property `node` - -the file that was affected -- **Type**: FSNodeContext -- **Mutability**: no-effect -- **Notes**: - #### Property `context` current context @@ -335,38 +411,37 @@ current context - **Notes**: -### `core.ip.validate` +### `ip.validate` This event is emitted when a validate is being validated. The event can be used to block certain validates from being validated. -#### Property `allow` +#### Property `res` -whether the operation is allowed -- **Type**: boolean +res +- **Type**: any - **Mutability**: mutable - **Notes**: - - If set to false, the ip will be considered invalid. -#### Property `ip` +#### Property `end_` -ip +end +- **Type**: any +- **Mutability**: mutable +- **Notes**: + +#### Property `end` + +end - **Type**: any - **Mutability**: mutable - **Notes**: -### `core.outer.fs.write-hash` +### `outer.fs.write-hash` This event is emitted when a write-hash is updated. -#### Property `hash` - -hash -- **Type**: any -- **Mutability**: no-effect -- **Notes**: - #### Property `uuid` uuid @@ -375,17 +450,10 @@ uuid - **Notes**: -### `core.outer.gui.item.added` +### `outer.gui.item.added` This event is emitted for outer gui item added operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -394,17 +462,10 @@ response - **Notes**: -### `core.outer.gui.item.moved` +### `outer.gui.item.moved` This event is emitted for outer gui item moved operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -413,17 +474,10 @@ response - **Notes**: -### `core.outer.gui.item.pending` +### `outer.gui.item.pending` This event is emitted for outer gui item pending operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -432,17 +486,10 @@ response - **Notes**: -### `core.outer.gui.item.updated` +### `outer.gui.item.updated` This event is emitted when a updated is updated. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -451,17 +498,10 @@ response - **Notes**: -### `core.outer.gui.notif.ack` +### `outer.gui.notif.ack` This event is emitted for outer gui notif ack operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -470,17 +510,10 @@ response - **Notes**: -### `core.outer.gui.notif.message` +### `outer.gui.notif.message` This event is emitted for outer gui notif message operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -496,17 +529,10 @@ notification - **Notes**: -### `core.outer.gui.notif.persisted` +### `outer.gui.notif.persisted` This event is emitted for outer gui notif persisted operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -515,17 +541,10 @@ response - **Notes**: -### `core.outer.gui.notif.unreads` +### `outer.gui.notif.unreads` This event is emitted for outer gui notif unreads operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -534,17 +553,10 @@ response - **Notes**: -### `core.outer.gui.submission.done` +### `outer.gui.submission.done` This event is emitted for outer gui submission done operations. -#### Property `user_id_list` - -user id list -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `response` response @@ -553,11 +565,109 @@ response - **Notes**: -### `core.puter-exec.submission.done` +### `outer.gui.usage.update` -This event is emitted for puter-exec submission done operations. +This event is emitted when a update is updated. -### `core.sns` + +### `outer.thread.notify-subscribers` + +This event is emitted for outer thread notify subscribers operations. + +#### Property `uid` + +uid +- **Type**: string +- **Mutability**: no-effect +- **Notes**: + +#### Property `action` + +action +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + +#### Property `data` + +data +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + + +### `puter.signup` + +This event is emitted for puter signup operations. + +#### Property `ip` + +ip +- **Type**: any +- **Mutability**: mutable +- **Notes**: + +#### Property `user_agent` + +user agent +- **Type**: any +- **Mutability**: mutable +- **Notes**: + +#### Property `body` + +body +- **Type**: any +- **Mutability**: mutable +- **Notes**: + + +### `request.measured` + +This event is emitted for request measured operations. + +#### Property `req` + +req +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + +#### Property `res` + +res +- **Type**: any +- **Mutability**: no-effect +- **Notes**: + + +### `request.will-be-handled` + +This event is emitted for request will be handled operations. + +#### Property `res` + +res +- **Type**: any +- **Mutability**: mutable +- **Notes**: + +#### Property `end_` + +end +- **Type**: any +- **Mutability**: mutable +- **Notes**: + +#### Property `end` + +end +- **Type**: any +- **Mutability**: mutable +- **Notes**: + + +### `sns` This event is emitted for sns operations. @@ -569,29 +679,15 @@ message - **Notes**: -### `core.template-service.hello` +### `template-service.hello` This event is emitted for template-service hello operations. -#### Property `message` -message -- **Type**: any -- **Mutability**: no-effect -- **Notes**: - - -### `core.usages.query` +### `usages.query` This event is emitted for usages query operations. -#### Property `actor` - -actor -- **Type**: any -- **Mutability**: no-effect -- **Notes**: - #### Property `usages` usages @@ -600,17 +696,10 @@ usages - **Notes**: -### `core.user.email-changed` +### `user.email-changed` This event is emitted for user email changed operations. -#### Property `user_id` - -user id -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `new_email` new email @@ -619,17 +708,10 @@ new email - **Notes**: -### `core.user.email-confirmed` +### `user.email-confirmed` This event is emitted for user email confirmed operations. -#### Property `user_uid` - -user uid -- **Type**: string -- **Mutability**: no-effect -- **Notes**: - #### Property `email` email @@ -638,7 +720,7 @@ email - **Notes**: -### `core.user.save_account` +### `user.save_account` This event is emitted for user save_account operations. @@ -650,17 +732,10 @@ user associated with the operation - **Notes**: -### `core.web.socket.connected` +### `web.socket.connected` This event is emitted for web socket connected operations. -#### Property `socket` - -socket -- **Type**: any -- **Mutability**: mutable -- **Notes**: - #### Property `user` user associated with the operation @@ -669,17 +744,10 @@ user associated with the operation - **Notes**: -### `core.web.socket.user-connected` +### `web.socket.user-connected` This event is emitted for web socket user connected operations. -#### Property `socket` - -socket -- **Type**: any -- **Mutability**: mutable -- **Notes**: - #### Property `user` user associated with the operation @@ -688,17 +756,10 @@ user associated with the operation - **Notes**: -### `core.wisp.get-policy` +### `wisp.get-policy` This event is emitted for wisp get policy operations. -#### Property `allow` - -whether the operation is allowed -- **Type**: boolean -- **Mutability**: mutable -- **Notes**: - #### Property `policy` policy information for the operation diff --git a/mods/mods_available/testex.js b/mods/mods_available/testex.js index ce1c9bf56..18bc781c4 100644 --- a/mods/mods_available/testex.js +++ b/mods/mods_available/testex.js @@ -1,158 +1,158 @@ // Test extension for event listeners -extension.on('core.ai.prompt.check-usage', event => { +extension.on('ai.prompt.check-usage', event => { console.log('GOT AI.PROMPT.CHECK-USAGE EVENT', event); }); -extension.on('core.ai.prompt.complete', event => { +extension.on('ai.prompt.complete', event => { console.log('GOT AI.PROMPT.COMPLETE EVENT', event); }); -extension.on('core.ai.prompt.report-usage', event => { +extension.on('ai.prompt.report-usage', event => { console.log('GOT AI.PROMPT.REPORT-USAGE EVENT', event); }); -extension.on('core.ai.prompt.validate', event => { +extension.on('ai.prompt.validate', event => { console.log('GOT AI.PROMPT.VALIDATE EVENT', event); }); -extension.on('core.app.new-icon', event => { +extension.on('app.new-icon', event => { console.log('GOT APP.NEW-ICON EVENT', event); }); -extension.on('core.app.rename', event => { +extension.on('app.rename', event => { console.log('GOT APP.RENAME EVENT', event); }); -extension.on('core.apps.invalidate', event => { +extension.on('apps.invalidate', event => { console.log('GOT APPS.INVALIDATE EVENT', event); }); -extension.on('core.email.validate', event => { +extension.on('email.validate', event => { console.log('GOT EMAIL.VALIDATE EVENT', event); }); -extension.on('core.fs.create.directory', event => { +extension.on('fs.create.directory', event => { console.log('GOT FS.CREATE.DIRECTORY EVENT', event); }); -extension.on('core.fs.create.file', event => { +extension.on('fs.create.file', event => { console.log('GOT FS.CREATE.FILE EVENT', event); }); -extension.on('core.fs.create.shortcut', event => { +extension.on('fs.create.shortcut', event => { console.log('GOT FS.CREATE.SHORTCUT EVENT', event); }); -extension.on('core.fs.create.symlink', event => { +extension.on('fs.create.symlink', event => { console.log('GOT FS.CREATE.SYMLINK EVENT', event); }); -extension.on('core.fs.move.file', event => { +extension.on('fs.move.file', event => { console.log('GOT FS.MOVE.FILE EVENT', event); }); -extension.on('core.fs.pending.file', event => { +extension.on('fs.pending.file', event => { console.log('GOT FS.PENDING.FILE EVENT', event); }); -extension.on('core.fs.storage.progress.copy', event => { +extension.on('fs.storage.progress.copy', event => { console.log('GOT FS.STORAGE.PROGRESS.COPY EVENT', event); }); -extension.on('core.fs.storage.upload-progress', event => { +extension.on('fs.storage.upload-progress', event => { console.log('GOT FS.STORAGE.UPLOAD-PROGRESS EVENT', event); }); -extension.on('core.fs.write.file', event => { +extension.on('fs.write.file', event => { console.log('GOT FS.WRITE.FILE EVENT', event); }); -extension.on('core.ip.validate', event => { +extension.on('ip.validate', event => { console.log('GOT IP.VALIDATE EVENT', event); }); -extension.on('core.outer.fs.write-hash', event => { +extension.on('outer.fs.write-hash', event => { console.log('GOT OUTER.FS.WRITE-HASH EVENT', event); }); -extension.on('core.outer.gui.item.added', event => { +extension.on('outer.gui.item.added', event => { console.log('GOT OUTER.GUI.ITEM.ADDED EVENT', event); }); -extension.on('core.outer.gui.item.moved', event => { +extension.on('outer.gui.item.moved', event => { console.log('GOT OUTER.GUI.ITEM.MOVED EVENT', event); }); -extension.on('core.outer.gui.item.pending', event => { +extension.on('outer.gui.item.pending', event => { console.log('GOT OUTER.GUI.ITEM.PENDING EVENT', event); }); -extension.on('core.outer.gui.item.updated', event => { +extension.on('outer.gui.item.updated', event => { console.log('GOT OUTER.GUI.ITEM.UPDATED EVENT', event); }); -extension.on('core.outer.gui.notif.ack', event => { +extension.on('outer.gui.notif.ack', event => { console.log('GOT OUTER.GUI.NOTIF.ACK EVENT', event); }); -extension.on('core.outer.gui.notif.message', event => { +extension.on('outer.gui.notif.message', event => { console.log('GOT OUTER.GUI.NOTIF.MESSAGE EVENT', event); }); -extension.on('core.outer.gui.notif.persisted', event => { +extension.on('outer.gui.notif.persisted', event => { console.log('GOT OUTER.GUI.NOTIF.PERSISTED EVENT', event); }); -extension.on('core.outer.gui.notif.unreads', event => { +extension.on('outer.gui.notif.unreads', event => { console.log('GOT OUTER.GUI.NOTIF.UNREADS EVENT', event); }); -extension.on('core.outer.gui.submission.done', event => { +extension.on('outer.gui.submission.done', event => { console.log('GOT OUTER.GUI.SUBMISSION.DONE EVENT', event); }); -extension.on('core.puter-exec.submission.done', event => { +extension.on('puter-exec.submission.done', event => { console.log('GOT PUTER-EXEC.SUBMISSION.DONE EVENT', event); }); -extension.on('core.request.measured', event => { +extension.on('request.measured', event => { console.log('GOT REQUEST.MEASURED EVENT', event); }); -extension.on('core.sns', event => { +extension.on('sns', event => { console.log('GOT SNS EVENT', event); }); -extension.on('core.template-service.hello', event => { +extension.on('template-service.hello', event => { console.log('GOT TEMPLATE-SERVICE.HELLO EVENT', event); }); -extension.on('core.usages.query', event => { +extension.on('usages.query', event => { console.log('GOT USAGES.QUERY EVENT', event); }); -extension.on('core.user.email-changed', event => { +extension.on('user.email-changed', event => { console.log('GOT USER.EMAIL-CHANGED EVENT', event); }); -extension.on('core.user.email-confirmed', event => { +extension.on('user.email-confirmed', event => { console.log('GOT USER.EMAIL-CONFIRMED EVENT', event); }); -extension.on('core.user.save_account', event => { +extension.on('user.save_account', event => { console.log('GOT USER.SAVE_ACCOUNT EVENT', event); }); -extension.on('core.web.socket.connected', event => { +extension.on('web.socket.connected', event => { console.log('GOT WEB.SOCKET.CONNECTED EVENT', event); }); -extension.on('core.web.socket.user-connected', event => { +extension.on('web.socket.user-connected', event => { console.log('GOT WEB.SOCKET.USER-CONNECTED EVENT', event); }); -extension.on('core.wisp.get-policy', event => { +extension.on('wisp.get-policy', event => { console.log('GOT WISP.GET-POLICY EVENT', event); }); diff --git a/src/backend/src/ExtensionService.js b/src/backend/src/ExtensionService.js index 192a71433..2c9cf1f9d 100644 --- a/src/backend/src/ExtensionService.js +++ b/src/backend/src/ExtensionService.js @@ -94,7 +94,13 @@ class ExtensionService extends BaseService { svc_event.on_all(async (key, data, meta = {}) => { meta.from_outside_of_extension = true; - await this.state.extension.emit(`core.${key}`, data, meta); + // register for both `core.` and the extension name + const promises = []; + promises.push( + this.state.extension.emit(`core.${key}`, data, meta)); + promises.push( + this.state.extension.emit(key, data, meta)); + await Promise.all(promises); }); this.state.extension.on_all(async (key, data, meta) => { diff --git a/tools/doc_helper.js b/tools/doc_helper.js index d285676e7..25ac173e8 100644 --- a/tools/doc_helper.js +++ b/tools/doc_helper.js @@ -32,6 +32,7 @@ function checkForDuplicateEvent(eventId, filePath, seenEvents) { function extractEventsFromFile(filePath, seenEvents, debugMode) { const content = fs.readFileSync(filePath, 'utf-8'); + // Use a more general regex to capture all event emissions // This captures the event name and whatever is passed as the second argument @@ -40,7 +41,7 @@ function extractEventsFromFile(filePath, seenEvents, debugMode) { while ((match = regex.exec(content)) !== null) { const eventName = match[1]; - const eventId = `core.${eventName}`; + const eventId = eventName; const eventArg = match[2].trim(); // Check if this file contains code that might affect event.allow @@ -103,10 +104,24 @@ function extractEventsFromFile(filePath, seenEvents, debugMode) { // Helper function to extract properties from a properties text string function extractProperties(propertiesText, propertyDetails, hasAllowEffect, eventName) { - const properties = propertiesText + // filter out all comments (lines starting with //) + const lines = propertiesText.split('\n').map(line => line.trim()).filter(line => !line.startsWith('//')); + + // glue all lines together, then split by commas + const gluedTest = lines.join('\n'); + + const properties = gluedTest .split(/\s*,\s*/) - .map(prop => prop.split(':')[0].trim()) + .map(prop => prop.split(/[^_A-Za-z0-9]/)[0].trim()) .filter(prop => prop); + + // // const event = { allow: true, email }; + // // text: allow: true, email + // // split to: [allow: true] [email] + // const properties = propertiesText + // .split(/\s*,\s*/) + // .map(prop => prop.split(':')[0].trim()) + // .filter(prop => prop); // Generate property details properties.forEach(prop => { @@ -216,6 +231,8 @@ function main() { const args = process.argv.slice(2); if (args.length < 1) { console.error('Usage: node doc_helper.js [output_file] [--generate-test] [--test-dir=] [--debug]'); + // node tools/doc_helper.js . doc/contributors/extensions/events.json.js + // [output_file] [--generate-test] [--test-dir=] [--debug]'); process.exit(1); }