@mochabug/adaptkit 0.1.0-alpha.29 → 0.1.0-alpha.30

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 (2) hide show
  1. package/bin/index.js +1 -1
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -47,7 +47,7 @@ var internalConfigTemplate = "import { InternalConfiguratorRouter } from '@mocha
47
47
 
48
48
  var browserExecTempalte = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of ExternalExecutorRouter and sets up routes to handle POST and GET requests.\n *\n * @name router\n * @type {ExternalExecutorRouter}\n */\nexport const router = new ExternalExecutorRouter()\n\n /**\n * Sets up a POST route at the '/api/done' endpoint.\n * This route checks the authorization status before allowing the action to complete.\n *\n * @method add\n * @async\n * @param {Request} _req - The incoming request object. This parameter is ignored in this function.\n * @param {ExecutorApi} api - The api object to interact with the system.\n * @param {RouteInfo} route - The route information. This parameter is ignored in this function.\n * @param {ExecutionContext} ctx - The context of execution to handle lifecycle events.\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/api/done', async (req, api, route, ctx) => {\n const authHeader = req.headers.get('Authorization')!;\n const authorized = await api.authorize(authHeader);\n if (!authorized.ok) {\n return new Response('Unauthorized', { status: 401 });\n }\n // We need the privileged api to communicate with the session\n const sapi = api.getSessionApi(authHeader);\n ctx.waitUntil(sapi.complete('output', {}));\n return new Response();\n })\n\n /**\n * Sets up a GET route at the root endpoint.\n * This route responds with a sample HTML page.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object with the HTML content and the appropriate headers.\n */\n .add('GET', '(/?)', async () => {\n return new Response(getSamplePage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\nfunction getSamplePage(): string {\n return `\n <html>\n <head>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');\n @keyframes glow {\n 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }\n 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }\n }\n body {\n background-color: #000;\n color: #0f0;\n font-family: 'Orbitron', sans-serif;\n text-align: center;\n overflow: hidden;\n margin: 0;\n padding: 0;\n }\n button {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background-color: #0f0;\n border: none;\n color: black;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 20px;\n margin: 4px 2px;\n cursor: pointer;\n transition-duration: 0.4s;\n animation: glow 2s infinite alternate;\n font-family: 'Orbitron', sans-serif;\n border-radius: 15px;\n transform: rotate(-10deg) skew(10deg, 10deg);\n }\n </style>\n </head>\n <body>\n <button id=\"doneButton\">Done</button>\n <script>\n document.getElementById('doneButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/done', {\n method: 'POST',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(data => {\n this.innerText = 'Done';\n })\n .catch(error => {\n console.error('Error:', error);\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
49
49
 
50
- var cronExecTemplate = "import { InternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of InternalExecutorRouter and sets up event handlers for all internal execution events.\n *\n * @name router\n * @type {InternalExecutorRouter}\n */\nexport const router = new InternalExecutorRouter()\n /**\n * Sets up a handler for the start event.\n * The handler is called when the execution of a vertex starts.\n *\n * @method onStart\n * @async\n */\n .onStart(async (req, api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n /**\n * Sets up a handler for the stop event.\n * This route is called when the vertex is forcibly stopped.\n * I.e. a trigger that is closed or a session that is forcibly closed.\n *\n * @method onStop\n * @async\n */\n .onStop(async (req, api) => {\n console.log('Stop has been called');\n })\n /**\n * Sets up a handler for the cron event.\n * This route is called when the cron trigger is fired.\n *\n * @method onCron\n * @async\n */\n .onCron(async (req, api) => {\n console.log('Received cron event');\n })\n /**\n * Sets up a handler for the stream event.\n * This route is called when stream content is available.\n *\n * @method onStream\n * @async\n */\n .onStream(async (req, api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n\n /**\n * Sets up a handler for the procedure event.\n * This route is called when procedure result is available.\n *\n * @method onProcedure\n * @async\n */\n .onProcedure(async (req, api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
50
+ var cronExecTemplate = "import { CronExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of CronExecutorRouter and sets up event handlers for all internal execution events.\n *\n * @name router\n * @type {CronExecutorRouter}\n */\nexport const router = new CronExecutorRouter()\n /**\n * Sets up a handler for the start event.\n * The handler is called when the execution of a vertex starts.\n *\n * @method onStart\n * @async\n */\n .onStart(async (req, api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n /**\n * Sets up a handler for the stop event.\n * This route is called when the vertex is forcibly stopped.\n * I.e. a trigger that is closed or a session that is forcibly closed.\n *\n * @method onStop\n * @async\n */\n .onStop(async (req, api) => {\n console.log('Stop has been called');\n })\n /**\n * Sets up a handler for the cron event.\n * This route is called when the cron trigger is fired.\n *\n * @method onCron\n * @async\n */\n .onCron(async (req, api) => {\n console.log('Received cron event');\n })\n /**\n * Sets up a handler for the stream event.\n * This route is called when stream content is available.\n *\n * @method onStream\n * @async\n */\n .onStream(async (req, api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n\n /**\n * Sets up a handler for the procedure event.\n * This route is called when procedure result is available.\n *\n * @method onProcedure\n * @async\n */\n .onProcedure(async (req, api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
51
51
 
52
52
  var triggerExecTemplate = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of ExternalExecutorRouter and sets up a wildcard route to handle all requests.\n * This wildcard route makes this router capable of receiving any type of HTTP request on any route.\n * It's important to note that this generic handling might not be suitable for all webhook scenarios.\n * For instance, some webhooks might require specific routes or specific types of requests.\n * In these cases, you should add specific routes to handle these scenarios.\n *\n * @name router\n */\nexport const router = new ExternalExecutorRouter()\n /**\n * Sets up a wildcard route that matches any HTTP method and any URL pattern.\n * This route is ideal for handling webhooks, which often send POST requests to a specific URL.\n * Here are a few examples of common webhook scenarios:\n * 1. GitHub sends a POST request to /github-webhook every time a new issue is created in your repository.\n * 2. Stripe sends a POST request to /stripe-webhook whenever a new payment is received.\n * 3. Twilio sends a POST request to /sms-webhook whenever an incoming SMS message is received.\n * For these scenarios, you should add specific routes that match these patterns (e.g., POST /github-webhook).\n *\n * Also, it's important to ensure that your webhooks are secure. One common way to do this is by validating the payload signature.\n * Most platforms sending webhooks provide a signature in the request headers that can be used to verify that the payload was not tampered with.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object with a sample HTML page.\n */\n .add('*', '(.*)', async () => {\n return new Response();\n });";
53
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adaptkit",
3
- "version": "0.1.0-alpha.29",
3
+ "version": "0.1.0-alpha.30",
4
4
  "description": "A cmd to create, emulate and publish Mochabug Adapt plugins",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",