@mochabug/adaptkit 0.1.0-alpha.27 → 0.1.0-alpha.28
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.
- package/bin/index.js +5 -5
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -41,17 +41,17 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
var externalConfigTemplate = "import { VertexConfig } from '@mochabug/adapt-plugin-toolkit/api';\nimport { ConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n *
|
|
44
|
+
var externalConfigTemplate = "import { VertexConfig } from '@mochabug/adapt-plugin-toolkit/api';\nimport { ConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Instantiates the ConfiguratorRouter for configuring routes.\n *\n * @type {ConfiguratorRouter}\n */\nexport const router = new ConfiguratorRouter()\n\n /**\n * Configures a GET route at the '/api/config' endpoint for authorization\n * and fetching the vertex configuration.\n *\n * @async\n * @returns {Response} Response containing authorization status or vertex configuration.\n */\n\n .add('GET', '/api/config', async (_, api) => {\n const authorized = await api.authorize();\n if (!authorized.ok) {\n return new Response('Unauthorized', { status: 401 });\n }\n\n const res = await api.getVertexConfig<VertexConfig>();\n if (!res.ok) {\n console.error(res);\n return new Response(res.errorMessage, { status: res.errorStatus });\n }\n return new Response(JSON.stringify(res.data!.item), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n })\n\n /**\n * Configures a GET route at the root endpoint to serve the \"Hello World\" page.\n *\n * @async\n * @returns {Response} Response containing the \"Hello World\" page content.\n */\n .add('GET', '(/?)', async () => {\n return new Response(getHelloWorldPage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\n/**\n * Generates and returns the HTML content for a \"Hello World\" page.\n *\n * @returns {string} HTML content of the \"Hello World\" page.\n */\nfunction getHelloWorldPage(): 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 h1 {\n position: absolute;\n top: 30%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 3em;\n text-transform: uppercase;\n letter-spacing: 4px;\n animation: glow 2s infinite alternate;\n }\n #jsonOutput {\n position: absolute;\n top: 70%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 1.5em;\n text-transform: uppercase;\n letter-spacing: 2px;\n animation: glow 2s infinite alternate;\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; /* Increase the font size */\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 <h1>Hello, World!</h1>\n <button id=\"assimilateButton\">Assimilate</button>\n <pre id=\"jsonOutput\"></pre>\n <script>\n document.getElementById('assimilateButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/config', {\n method: 'GET',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(response => response.json())\n .then(data => {\n document.getElementById('jsonOutput').innerText = JSON.stringify(data, null, 2);\n this.style.display = 'none'; /* Hide button after being clicked */\n })\n .catch(error => {\n console.error('Error:', error);\n document.getElementById('jsonOutput').innerText = 'Error occurred while assimilating data';\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
|
|
45
45
|
|
|
46
46
|
var internalConfigTemplate = "import { ConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * This module provides the internal configuration endpoint for a vertex.\n * \n * The `router` exported from this module is an instance of `ConfiguratorRouter`, \n * which has been configured to respond to all HTTP methods at any route with a \n * simple HTTP response.\n * \n * The purpose of this endpoint is to receive and handle internal platform calls,\n * which notify the vertex of various events during the configuration process.\n *\n * @module configurator\n */\n\n/**\n * A `ConfiguratorRouter` instance configured to handle internal platform calls for the vertex.\n * \n * This router responds to any HTTP method and route with a simple HTTP response.\n * It's intended to serve as an internal configuration endpoint within a flow-graph.\n * \n * @see ConfiguratorRouter\n */\nexport const router = new ConfiguratorRouter()\n .add('*', '(.*)', async () => new Response());";
|
|
47
47
|
|
|
48
|
-
var browserExecTempalte = "import {
|
|
48
|
+
var browserExecTempalte = "import { BasicExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of BasicExecutorRouter and sets up routes to handle POST and GET requests.\n *\n * @name router\n * @type {BasicExecutorRouter}\n */\nexport const router = new BasicExecutorRouter()\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 authorized = await api.authorize();\n if (!authorized.ok) {\n return new Response('Unauthorized', { status: 401 });\n }\n // This will fetch the privileged api using the bearer token\n const papi = api.getPrivilegedApi();\n ctx.waitUntil(papi.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 {
|
|
50
|
+
var cronExecTemplate = "import { PrivilegedExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of PrivilegedExecutorRouter and sets up routes to handle POST requests for execution events.\n *\n * @name router\n * @type {PrivilegedExecutorRouter}\n */\nexport const router = new PrivilegedExecutorRouter()\n\n /**\n * Sets up a POST route at the '/start' endpoint.\n * This route is called when the execution of a vertex starts.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/start', async (req) => {\n const start = await req.json<StartExecutionRequest>();\n console.log(start)\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/stop' endpoint.\n * This route is called when the execution of a vertex stops.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/stop', async () => {\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/cron' endpoint.\n * This route is called at a periodic interval specified by the vertex configuration.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object to acknowledge receipt of the cron execution command.\n */\n .add('POST', '/cron', async () => {\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/streams/:name' endpoint.\n * This route is called when stream content is required for a named stream.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/streams/:name', async (req) => {\n const res = await req.json<ExchangeResult>();\n console.log(res)\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/procedures/:name' endpoint.\n * This route is called when procedure content is required for a named procedure.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/procedures/:name', async (req) => {\n const res = await req.json<ExchangeResult>();\n console.log(res)\n return new Response();\n });";
|
|
51
51
|
|
|
52
|
-
var triggerExecTemplate = "import {
|
|
52
|
+
var triggerExecTemplate = "import { BasicExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of BasicExecutorRouter 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 * @type {BasicExecutorRouter}\n */\nexport const router = new BasicExecutorRouter()\n\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
|
|
|
54
|
-
var internalExecTemplate = "import {
|
|
54
|
+
var internalExecTemplate = "import { PrivilegedExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\n/**\n * Constructs an instance of PrivilegedExecutorRouter and sets up routes to handle POST requests for execution, streams, and procedures.\n *\n * @name router\n * @type {PrivilegedExecutorRouter}\n */\nexport const router = new PrivilegedExecutorRouter()\n\n /**\n * Sets up a POST route at the '/start' endpoint.\n * This route is called when the execution of a vertex starts.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/start', async (req) => {\n const start = await req.json<StartExecutionRequest>();\n console.log(start)\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/stop' endpoint.\n * This route is called when the execution of a vertex stops.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/stop', async () => {\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/streams/:name' endpoint.\n * This route is called when stream content is required for a named stream.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/streams/:name', async (req) => {\n const res = await req.json<ExchangeResult>();\n console.log(res)\n return new Response();\n })\n\n /**\n * Sets up a POST route at the '/procedures/:name' endpoint.\n * This route is called when procedure content is required for a named procedure.\n *\n * @method add\n * @async\n * @returns {Response} Returns a response object.\n */\n .add('POST', '/procedures/:name', async (req) => {\n const res = await req.json<ExchangeResult>();\n console.log(res)\n return new Response();\n });\n";
|
|
55
55
|
|
|
56
56
|
var gitignoreTemplate = "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n.pnpm-debug.log*\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\nreport.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n*.lcov\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# Snowpack dependency directory (https://snowpack.dev/)\nweb_modules/\n\n# TypeScript cache\n*.tsbuildinfo\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional stylelint cache\n.stylelintcache\n\n# Microbundle cache\n.rpt2_cache/\n.rts2_cache_cjs/\n.rts2_cache_es/\n.rts2_cache_umd/\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variable files\n.env\n.env.development.local\n.env.test.local\n.env.production.local\n.env.local\n\n# parcel-bundler cache (https://parceljs.org/)\n.cache\n.parcel-cache\n\n# Next.js build output\n.next\nout\n\n# Nuxt.js build / generate output\n.nuxt\ndist\nbuild\n\n# Gatsby files\n.cache/\n# Comment in the public line in if your project uses Gatsby and not Next.js\n# https://nextjs.org/blog/next-9-1#public-directory-support\n# public\n\n# vuepress build output\n.vuepress/dist\n\n# vuepress v2.x temp and cache directory\n.temp\n.cache\n\n# Stores VSCode versions used for testing VSCode extensions\n.vscode-test\n\n# yarn v2\n.yarn/cache\n.yarn/unplugged\n.yarn/build-state.yml\n.yarn/install-state.gz\n.pnp.*";
|
|
57
57
|
|