@mochabug/adaptkit 1.0.0-rc.4 → 1.0.0-rc.41

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 (89) hide show
  1. package/README.md +50 -45
  2. package/assets/build.js +2 -57
  3. package/assets/configurator.html +14 -0
  4. package/assets/configurator.ssg.tsx +2 -16
  5. package/assets/configurator_none.ts +8 -8
  6. package/assets/configurator_react.tsx +14 -11
  7. package/assets/executor.html +14 -0
  8. package/assets/executor.ssg.tsx +2 -16
  9. package/assets/executor_action.ts +4 -8
  10. package/assets/{executor_cron_trigger.ts → executor_action_cron.ts} +4 -8
  11. package/assets/executor_browser_none.ts +9 -13
  12. package/assets/executor_browser_none_cron.ts +119 -0
  13. package/assets/executor_browser_react.tsx +15 -16
  14. package/assets/executor_browser_react_cron.tsx +55 -0
  15. package/assets/{executor_external_trigger.ts → executor_external.ts} +8 -12
  16. package/assets/executor_external_cron.ts +45 -0
  17. package/assets/gitignore +3 -1
  18. package/assets/tsconf.json +4 -7
  19. package/bin/add.d.ts +3 -0
  20. package/bin/add.d.ts.map +1 -0
  21. package/bin/genproto/buf/validate/validate_pb.d.ts +8491 -0
  22. package/bin/genproto/buf/validate/validate_pb.d.ts.map +1 -0
  23. package/bin/genproto/google/api/annotations_pb.d.ts +14 -0
  24. package/bin/genproto/google/api/annotations_pb.d.ts.map +1 -0
  25. package/bin/genproto/google/api/client_pb.d.ts +1432 -0
  26. package/bin/genproto/google/api/client_pb.d.ts.map +1 -0
  27. package/bin/genproto/google/api/http_pb.d.ts +843 -0
  28. package/bin/genproto/google/api/http_pb.d.ts.map +1 -0
  29. package/bin/genproto/google/api/launch_stage_pb.d.ts +94 -0
  30. package/bin/genproto/google/api/launch_stage_pb.d.ts.map +1 -0
  31. package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts +77 -0
  32. package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts.map +1 -0
  33. package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts +401 -0
  34. package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts.map +1 -0
  35. package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts +69 -0
  36. package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts.map +1 -0
  37. package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts +430 -0
  38. package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts.map +1 -0
  39. package/bin/genproto/mochabugapis/adapt/graph/signal_data_pb.d.ts +198 -0
  40. package/bin/genproto/mochabugapis/adapt/graph/signal_data_pb.d.ts.map +1 -0
  41. package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts +161 -0
  42. package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts.map +1 -0
  43. package/bin/genproto/mochabugapis/adapt/graph/signal_format_pb.d.ts +305 -0
  44. package/bin/genproto/mochabugapis/adapt/graph/signal_format_pb.d.ts.map +1 -0
  45. package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts +77 -0
  46. package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts.map +1 -0
  47. package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts +120 -0
  48. package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts.map +1 -0
  49. package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts +99 -0
  50. package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts.map +1 -0
  51. package/bin/genproto/mochabugapis/adapt/plugins/v1/compound_services_pb.d.ts +347 -0
  52. package/bin/genproto/mochabugapis/adapt/plugins/v1/compound_services_pb.d.ts.map +1 -0
  53. package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts +64 -0
  54. package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts.map +1 -0
  55. package/bin/genproto/mochabugapis/adapt/plugins/v1/http_proxy_service_pb.d.ts +1282 -0
  56. package/bin/genproto/mochabugapis/adapt/plugins/v1/http_proxy_service_pb.d.ts.map +1 -0
  57. package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts +388 -0
  58. package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts.map +1 -0
  59. package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts +805 -0
  60. package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts.map +1 -0
  61. package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts +238 -0
  62. package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts.map +1 -0
  63. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts +241 -0
  64. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts.map +1 -0
  65. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_settings_pb.d.ts +539 -0
  66. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_settings_pb.d.ts.map +1 -0
  67. package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts +190 -0
  68. package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts.map +1 -0
  69. package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts +269 -0
  70. package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts.map +1 -0
  71. package/bin/index.d.ts +12 -0
  72. package/bin/index.d.ts.map +1 -0
  73. package/bin/index.js +846 -711
  74. package/bin/index.js.map +4 -4
  75. package/bin/init.d.ts +2 -0
  76. package/bin/init.d.ts.map +1 -0
  77. package/bin/oauth2.d.ts +2 -0
  78. package/bin/oauth2.d.ts.map +1 -0
  79. package/bin/publish.d.ts +27 -0
  80. package/bin/publish.d.ts.map +1 -0
  81. package/bin/utils.d.ts +13 -0
  82. package/bin/utils.d.ts.map +1 -0
  83. package/bin/vertices.d.ts +3 -0
  84. package/bin/vertices.d.ts.map +1 -0
  85. package/package.json +25 -27
  86. package/assets/build-client.js +0 -111
  87. package/assets/global.d.ts +0 -7
  88. package/assets/inject.js +0 -15
  89. package/assets/license.md +0 -15
package/README.md CHANGED
@@ -1,82 +1,87 @@
1
- # @mochabug/adaptkit : The Magical CLI for Mochabug Adapt Plugin Development!
1
+ # @mochabug/adaptkit
2
2
 
3
- Welcome to **@mochabug/adaptkit**! Prepare to embark on a whimsical adventure filled with creativity and efficiency! @mochabug/adaptkit is a powerful CLI tool designed to help you *effortlessly* develop and manage plugins for the Mochabug Adapt platform. With @mochabug/adaptkit, you can:
3
+ **@mochabug/adaptkit** is the official CLI tool for developing and managing plugins for the Mochabug Adapt platform. Built with Node.js 22 compatibility, adaptkit streamlines the entire plugin development workflow.
4
4
 
5
- - 🌈 Create enchanting template projects for plugin development
6
- - 🧙‍♂️ Emulate your plugins in a cloud environment with just a flick of your wand
7
- - 🧚 Add and modify vertices to your plugin project with ease
8
- - 🌟 Automagically handle tedious tasks that often bog down software development
5
+ ## Key Features
9
6
 
10
- ## Magical Vertices: Your Plugin Building Blocks 🔮
7
+ - Create new plugin projects with scaffolding
8
+ - Add vertices (tasks) to existing plugins
9
+ - Emulate plugins locally for testing
10
+ - Publish plugins to the Mochabug Adapt platform
11
+ - Manage plugin versioning with semantic versioning
11
12
 
12
- Vertices, also known as tasks, are the building blocks of your plugins. Each plugin consists of one or more vertices. A vertex in @mochabug/adaptkit consists of two parts: an Executor and an optional Configurator.
13
+ ## Plugin Architecture
13
14
 
14
- - **Executor**: A mandatory part that performs tasks. It can have different types:
15
- - **Action**: Performs tasks without interacting with external systems
16
- - **Cron Trigger**: Triggers actions at specified intervals, like clockwork
17
- - **External Trigger**: Activates tasks from an external endpoint, bringing the magic to the outside world
18
- - **Browser**: Runs tasks within a browser, where requests end up on the external endpoint
15
+ Plugins are composed of **vertices** - the fundamental building blocks that define tasks. Each vertex consists of:
19
16
 
20
- - **Configurator**: An optional part that customizes the behavior of the executor. Configurators interact with users on the Mochabug Adapt platform, making them "external" by nature.
17
+ ### Executor (Required)
18
+ The core logic that performs tasks. Available types:
19
+ - **Action** - Performs tasks without external system interactions
20
+ - **Cron Trigger** - Executes tasks at scheduled intervals
21
+ - **External Trigger** - Responds to external endpoint events
22
+ - **Browser** - Runs tasks within a browser environment
21
23
 
22
- ## Getting Started 🚀
24
+ ### Configurator (Optional)
25
+ Provides UI for customizing executor behavior on the Mochabug Adapt platform.
23
26
 
24
- To start your magical journey with @mochabug/adaptkit, install the package using the following incantation:
27
+ ## Installation
25
28
 
26
29
  ```bash
27
30
  npm install -g @mochabug/adaptkit
28
31
  ```
29
32
 
30
- ## Usage 🪄
31
-
32
- With @mochabug/adaptkit installed, you can now wield your newfound powers to develop and manage your plugin projects! Here's a guide to help you harness the magic:
33
-
34
- 1. **Create a template project for plugin development**
33
+ ## Commands
35
34
 
35
+ ### Initialize a Plugin Project
36
36
  ```bash
37
- adaptkit --init
37
+ adaptkit init
38
38
  ```
39
+ Creates a new plugin with `manifest.json`, executor/configurator templates, and schema files.
39
40
 
40
- This command generates a `manifest.json` file, Executor and Configurator templates, and .cue schema files with information about your plugin.
41
-
42
- 2. **Emulate your plugins in the cloud environment**
43
-
41
+ ### Add Vertices to Your Plugin
44
42
  ```bash
45
- adaptkit --emulate
43
+ adaptkit add
46
44
  ```
45
+ Interactively adds new vertices to your existing plugin project.
47
46
 
48
- Test your plugin's sorcery in a controlled environment by emulating its behavior in the cloud.
49
-
50
- In order to do this you need to have docker installed and run the emulator locally using the following command:
47
+ ### Emulate Plugin Locally
48
+ ```bash
49
+ adaptkit emulate
50
+ ```
51
+ Test your plugin in a local environment. Requires the Mochabug Adapt sandbox:
51
52
 
52
53
  ```bash
53
54
  docker run --rm -it -p 51001:51001 -p 51002:51002 -p 51003:51003 -p 51004:51004 -p 51005:51005 mochabug/adaptsandbox:latest
54
55
  ```
55
56
 
56
- Note: The 5 ports is required to simulate the different vertex types as well as the graphical interface together with the publish endpoint of adaptkit.
57
-
58
- 1. **Add and modify vertices**
57
+ The 5 ports simulate different vertex types, the graphical interface, and the adaptkit publish endpoint.
59
58
 
59
+ ### Publish to Mochabug Adapt
60
60
  ```bash
61
- adaptkit --add-vertex [vertexType] [vertexName]
61
+ adaptkit publish
62
62
  ```
63
+ Deploy your plugin to the Mochabug Adapt platform for production use.
63
64
 
64
- Easily add or modify vertices to your plugin project by specifying the vertex type and name.
65
-
66
- 4. **Publish your plugin to the Mochabug Adapt platform**
67
-
65
+ ### Version Management
68
66
  ```bash
69
- adaptkit --publish
67
+ adaptkit version --patch # Increment patch version
68
+ adaptkit version --minor # Increment minor version
69
+ adaptkit version --major # Increment major version
70
70
  ```
71
+ Updates the semantic version in your plugin's `manifest.json`.
72
+
73
+ ## Node.js 22 Compatibility
74
+
75
+ Adaptkit is built with full Node.js 22 support, leveraging modern JavaScript features and native ES modules for optimal performance and compatibility.
71
76
 
72
- Share your magical creation with the world by publishing your plugin to the Mochabug Adapt platform.
77
+ ## Documentation
73
78
 
74
- ## Documentation 📚
79
+ For comprehensive documentation and API references, visit [Mochabug Developer Portal](https://developers.mochabug.com).
75
80
 
76
- For a more comprehensive spellbook on how to use @mochabug/adaptkit and unlock the full potential of our captivating plugin system for Mochabug Adapt, visit our [documentation](https://developers.mochabug.com).
81
+ ## Contributing
77
82
 
78
- ## Contribute 🤝
83
+ We welcome community contributions! Please [open an issue](https://github.com/mochabug/adaptkit/issues) or [submit a pull request](https://github.com/mochabug/adaptkit/pulls) on GitHub.
79
84
 
80
- @mochabug/adaptkit s is a community-driven, open-source project, and we warmly welcome your contributions! If you have an idea for a new type, a bug report, or would like to help with documentation, please [open an issue](https://github.com/mochabug/mochabug/issues) or [submit a pull request](https://github.com/mochabug/mochabug/pulls).
85
+ ## License
81
86
 
82
- ## A Magical Journey Awaits! 🍄
87
+ Apache License 2.0
package/assets/build.js CHANGED
@@ -1,57 +1,2 @@
1
- import { cloudflare } from "@cloudflare/unenv-preset";
2
- import { build } from 'esbuild';
3
- import fs from 'node:fs';
4
- import { defineEnv } from 'unenv';
5
-
6
- if (!process.env.PLUGINS_CDN) {
7
- console.error('PLUGINS_CDN is required');
8
- process.exit(1);
9
- }
10
-
11
- // Load the manifest.json file and read organization, name and version of the plugin
12
- const manifest = JSON.parse(fs.readFileSync('./manifest.json', 'utf8'));
13
- if (!manifest.organization || !manifest.name || !manifest.version) {
14
- throw new Error('Manifest file is missing organization, name or version');
15
- }
16
- const CDN_PATH = `${process.env.PLUGINS_CDN}/${manifest.organization}/${manifest.name}/${manifest.version}`;
17
-
18
- const { env } = defineEnv({ nodeCompat: true, presets: [cloudflare] });
19
-
20
- const entryPoints = ['./src/executors']
21
- if (fs.existsSync('./src/configurators.ts')) {
22
- entryPoints.push('./src/configurators')
23
- }
24
-
25
- // Set up the defines, this will automatically load ssg index.html files if they exists
26
- const define = {
27
- PLUGINS_CDN: JSON.stringify(CDN_PATH)
28
- };
29
- if (fs.existsSync('./dist/configurator-index-html.json')) {
30
- const CONFIGURATOR_INDEX_HTML = fs.readFileSync('./dist/configurator-index-html.json', 'utf8');
31
- define.CONFIGURATOR_INDEX_HTML = CONFIGURATOR_INDEX_HTML;
32
- }
33
- if (fs.existsSync('./dist/executor-index-html.json')) {
34
- const EXECUTOR_INDEX_HTML = fs.readFileSync('./dist/executor-index-html.json', 'utf8');
35
- define.EXECUTOR_INDEX_HTML = EXECUTOR_INDEX_HTML;
36
- }
37
-
38
- await build({
39
- entryPoints,
40
- outdir: 'dist',
41
- bundle: true,
42
- minify: true,
43
- treeShaking: true,
44
- sourcemap: false,
45
- splitting: false,
46
- format: 'esm',
47
- platform: 'node',
48
- target: 'esnext',
49
- tsconfig: 'tsconfig.json',
50
- inject: ['./inject.js'],
51
- mainFields: ["module", "main"],
52
- conditions: ["workerd"],
53
- external: env.external,
54
- alias: env.alias,
55
- publicPath: CDN_PATH,
56
- define,
57
- });
1
+ import { build } from '@mochabug/adapt-builder';
2
+ build({ cdnBase: process.env.PLUGINS_CDN });
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>The configurator</title>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="root"><%= define.content %></div>
12
+ </body>
13
+
14
+ </html>
@@ -12,20 +12,6 @@ import React from 'react';
12
12
  import { renderToString } from 'react-dom/server';
13
13
  import App from './configurator.App';
14
14
 
15
- export default function (js: string, css?: string) {
16
- return `
17
- <!DOCTYPE html>
18
- <html lang="en">
19
- <head>
20
- <meta charset="utf-8" />
21
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
22
- <title>Title</title>
23
- ${css ? `<link rel="stylesheet" href="${css}" />` : ''}
24
- </head>
25
- <body>
26
- <div id="root">${renderToString(<App />)}</div>
27
- <script type="module" src="${js}"></script>
28
- </body>
29
- </html>
30
- `;
15
+ export default function () {
16
+ return renderToString(<App />);
31
17
  }
@@ -1,11 +1,11 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus
4
+ } from '@mochabug/adapt-sdk/api';
5
5
  import {
6
6
  ExternalConfiguratorRouter,
7
7
  InternalConfiguratorRouter
8
- } from '@mochabug/adapt-plugin-toolkit/router';
8
+ } from '@mochabug/adapt-sdk/router';
9
9
 
10
10
  export default {
11
11
  external: new ExternalConfiguratorRouter()
@@ -13,8 +13,8 @@ export default {
13
13
  .useBearerAuthorization(['/api'])
14
14
  .useErrorHandling(async (e) => {
15
15
  console.error(e);
16
- if (e instanceof RpcError) {
17
- return new Response(null, { status: mapErrorToHttpError(e.code) });
16
+ if (e instanceof ConnectError) {
17
+ return new Response(null, { status: mapConnectErrorToHttpStatus(e) });
18
18
  }
19
19
  return new Response(null, {
20
20
  status: 500,
@@ -22,8 +22,8 @@ export default {
22
22
  });
23
23
  })
24
24
  .add('GET', '/api/config', async (_req, api) => {
25
- const res = await api.getVertexConfig();
26
- return new Response(JSON.stringify(res.metadata), {
25
+ const { metadata } = await api.getConfig('metadata');
26
+ return new Response(JSON.stringify(metadata), {
27
27
  headers: {
28
28
  'Content-Type': 'application/json'
29
29
  }
@@ -1,11 +1,11 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus
4
+ } from '@mochabug/adapt-sdk/api';
5
5
  import {
6
6
  ExternalConfiguratorRouter,
7
7
  InternalConfiguratorRouter
8
- } from '@mochabug/adapt-plugin-toolkit/router';
8
+ } from '@mochabug/adapt-sdk/router';
9
9
 
10
10
  export default {
11
11
  external: new ExternalConfiguratorRouter()
@@ -13,8 +13,8 @@ export default {
13
13
  .useBearerAuthorization(['/api'])
14
14
  .useErrorHandling(async (e) => {
15
15
  console.error(e);
16
- if (e instanceof RpcError) {
17
- return new Response(null, { status: mapErrorToHttpError(e.code) });
16
+ if (e instanceof ConnectError) {
17
+ return new Response(null, { status: mapConnectErrorToHttpStatus(e) });
18
18
  }
19
19
  return new Response(null, {
20
20
  status: 500,
@@ -22,16 +22,19 @@ export default {
22
22
  });
23
23
  })
24
24
  .add('GET', '/api/config', async (_req, api) => {
25
- const res = await api.getVertexConfig();
26
- return new Response(JSON.stringify(res.metadata), {
25
+ const { metadata } = await api.getConfig('metadata');
26
+ return new Response(JSON.stringify(metadata), {
27
27
  headers: {
28
28
  'Content-Type': 'application/json'
29
29
  }
30
30
  });
31
31
  })
32
- .add('GET', '{*any}', async () => {
33
- return new Response(CONFIGURATOR_INDEX_HTML['___VERTEX_NAME___'], {
34
- headers: { 'Content-Type': 'text/html' }
32
+ .add('GET', '{/*any}', async (_, api) => {
33
+ const res = await api.readFile(
34
+ 'browser/___VERTEX_NAME___/configurator.html'
35
+ );
36
+ return new Response(res.content, {
37
+ headers: { 'Content-Type': 'text/html; charset=utf-8' }
35
38
  });
36
39
  }),
37
40
  internal: new InternalConfiguratorRouter()
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>The executor</title>
8
+ </head>
9
+
10
+ <body>
11
+ <div id="root"><%= define.content %></div>
12
+ </body>
13
+
14
+ </html>
@@ -12,20 +12,6 @@ import React from 'react';
12
12
  import { renderToString } from 'react-dom/server';
13
13
  import App from './executor.App';
14
14
 
15
- export default function (js: string, css?: string) {
16
- return `
17
- <!DOCTYPE html>
18
- <html lang="en">
19
- <head>
20
- <meta charset="utf-8" />
21
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
22
- <title>Title</title>
23
- ${css ? `<link rel="stylesheet" href="${css}" />` : ''}
24
- </head>
25
- <body>
26
- <div id="root">${renderToString(<App />)}</div>
27
- <script type="module" src="${js}"></script>
28
- </body>
29
- </html>
30
- `;
15
+ export default function () {
16
+ return renderToString(<App />);
31
17
  }
@@ -1,22 +1,18 @@
1
- import { InternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';
1
+ import { InternalExecutorRouter } from '@mochabug/adapt-sdk/router';
2
2
 
3
3
  export default {
4
4
  internal: new InternalExecutorRouter()
5
5
  .onStart(async (start, api, ctx) => {
6
6
  console.log('Start has been called');
7
7
  console.log(start);
8
- ctx.waitUntil(api.complete('output', {}));
8
+ ctx.waitUntil(api.send('output', {}));
9
9
  })
10
10
  .onStop(async (stop, _api) => {
11
11
  console.log('Stop has been called');
12
12
  console.log(stop);
13
13
  })
14
- .onStream(async (res, _api, name) => {
15
- console.log(`Stream ${name} has been called`);
16
- console.log(res);
17
- })
18
- .onProcedure(async (res, _api, name) => {
19
- console.log(`Procedure ${name} has been called`);
14
+ .onExchange(async (res, _api, name) => {
15
+ console.log(`Exchange ${name} has been called`);
20
16
  console.log(res);
21
17
  })
22
18
  };
@@ -1,4 +1,4 @@
1
- import { CronExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';
1
+ import { CronExecutorRouter } from '@mochabug/adapt-sdk/router';
2
2
 
3
3
  export default {
4
4
  internal: new CronExecutorRouter()
@@ -10,17 +10,13 @@ export default {
10
10
  console.log('Stop has been called');
11
11
  console.log(stop);
12
12
  })
13
- .onStream(async (res, _api, name) => {
14
- console.log(`Stream ${name} has been called`);
15
- console.log(res);
16
- })
17
- .onProcedure(async (res, _api, name) => {
18
- console.log(`Procedure ${name} has been called`);
13
+ .onExchange(async (res, _api, name) => {
14
+ console.log(`Exchange ${name} has been called`);
19
15
  console.log(res);
20
16
  })
21
17
  .onCron(async (cron, api, ctx) => {
22
18
  console.log('Received cron event');
23
- ctx.waitUntil(api.complete('output', {}));
19
+ ctx.waitUntil(api.send('output', {}));
24
20
  console.log(cron);
25
21
  })
26
22
  };
@@ -1,11 +1,11 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-sdk/api";
5
5
  import {
6
6
  ExternalExecutorRouter,
7
7
  InternalExecutorRouter
8
- } from '@mochabug/adapt-plugin-toolkit/router';
8
+ } from '@mochabug/adapt-sdk/router';
9
9
 
10
10
  export default {
11
11
  external: new ExternalExecutorRouter()
@@ -13,8 +13,8 @@ export default {
13
13
  .useBearerAuthorization(['/api'])
14
14
  .useErrorHandling(async (e) => {
15
15
  console.error(e);
16
- if (e instanceof RpcError) {
17
- return new Response(null, { status: mapErrorToHttpError(e.code) });
16
+ if (e instanceof ConnectError) {
17
+ return new Response(null, { status: mapConnectErrorToHttpStatus(e) });
18
18
  }
19
19
  return new Response(null, {
20
20
  status: 500,
@@ -23,7 +23,7 @@ export default {
23
23
  })
24
24
  .add('POST', '/api/done', async (req, api, _route, ctx) => {
25
25
  const sapi = api.getSessionApi(req.headers.get('Authorization')!);
26
- ctx.waitUntil(sapi.complete('output', {}));
26
+ ctx.waitUntil(sapi.send('output', {}));
27
27
  return new Response();
28
28
  })
29
29
  .add('GET', '{*any}', async () => {
@@ -42,12 +42,8 @@ export default {
42
42
  console.log('Stop has been called');
43
43
  console.log(stop);
44
44
  })
45
- .onStream(async (res, _api, name) => {
46
- console.log(`Stream ${name} has been called`);
47
- console.log(res);
48
- })
49
- .onProcedure(async (res, _api, name) => {
50
- console.log(`Procedure ${name} has been called`);
45
+ .onExchange(async (res, _api, name) => {
46
+ console.log(`Exchange ${name} has been called`);
51
47
  console.log(res);
52
48
  })
53
49
  };
@@ -0,0 +1,119 @@
1
+ import {
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-sdk/api";
5
+ import {
6
+ ExternalExecutorRouter,
7
+ CronExecutorRouter
8
+ } from '@mochabug/adapt-sdk/router';
9
+
10
+ export default {
11
+ external: new ExternalExecutorRouter()
12
+ .useRequestLogging()
13
+ .useBearerAuthorization(['/api'])
14
+ .useErrorHandling(async (e) => {
15
+ console.error(e);
16
+ if (e instanceof ConnectError) {
17
+ return new Response(null, { status: mapConnectErrorToHttpStatus(e) });
18
+ }
19
+ return new Response(null, {
20
+ status: 500,
21
+ statusText: 'Internal server error'
22
+ });
23
+ })
24
+ .add('POST', '/api/done', async (req, api, _route, ctx) => {
25
+ const sapi = api.getSessionApi(req.headers.get('Authorization')!);
26
+ ctx.waitUntil(sapi.send('output', {}));
27
+ return new Response();
28
+ })
29
+ .add('GET', '{*any}', async () => {
30
+ return new Response(helloWorld, {
31
+ headers: {
32
+ 'Content-Type': 'text/html'
33
+ }
34
+ });
35
+ }),
36
+ internal: new CronExecutorRouter()
37
+ .onStart(async (start, _api) => {
38
+ console.log('Start has been called');
39
+ console.log(start);
40
+ })
41
+ .onStop(async (stop, _api) => {
42
+ console.log('Stop has been called');
43
+ console.log(stop);
44
+ })
45
+ .onExchange(async (res, _api, name) => {
46
+ console.log(`Exchange ${name} has been called`);
47
+ console.log(res);
48
+ })
49
+ .onCron(async (cron, api, ctx) => {
50
+ console.log('Received cron event');
51
+ ctx.waitUntil(api.send('output', {}));
52
+ console.log(cron);
53
+ })
54
+ };
55
+
56
+ const helloWorld = `
57
+ <html>
58
+ <head>
59
+ <style>
60
+ @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');
61
+ @keyframes glow {
62
+ 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }
63
+ 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }
64
+ }
65
+ body {
66
+ background-color: #000;
67
+ color: #0f0;
68
+ font-family: 'Orbitron', sans-serif;
69
+ text-align: center;
70
+ overflow: hidden;
71
+ margin: 0;
72
+ padding: 0;
73
+ }
74
+ button {
75
+ position: absolute;
76
+ top: 50%;
77
+ left: 50%;
78
+ transform: translate(-50%, -50%);
79
+ background-color: #0f0;
80
+ border: none;
81
+ color: black;
82
+ padding: 15px 32px;
83
+ text-align: center;
84
+ text-decoration: none;
85
+ display: inline-block;
86
+ font-size: 20px;
87
+ margin: 4px 2px;
88
+ cursor: pointer;
89
+ transition-duration: 0.4s;
90
+ animation: glow 2s infinite alternate;
91
+ font-family: 'Orbitron', sans-serif;
92
+ border-radius: 15px;
93
+ transform: rotate(-10deg) skew(10deg, 10deg);
94
+ }
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <button id="doneButton">Done</button>
99
+ <script>
100
+ document.getElementById('doneButton').addEventListener('click', function() {
101
+ const hash = window.location.hash.substring(1).trim();
102
+ const token = decodeURIComponent(hash);
103
+ fetch('/api/done', {
104
+ method: 'POST',
105
+ headers: {
106
+ 'Authorization': 'Bearer ' + token
107
+ }
108
+ })
109
+ .then(data => {
110
+ this.innerText = 'Done';
111
+ })
112
+ .catch(error => {
113
+ console.error('Error:', error);
114
+ });
115
+ });
116
+ </script>
117
+ </body>
118
+ </html>
119
+ `;
@@ -1,11 +1,11 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-sdk/api";
5
5
  import {
6
6
  ExternalExecutorRouter,
7
7
  InternalExecutorRouter
8
- } from '@mochabug/adapt-plugin-toolkit/router';
8
+ } from '@mochabug/adapt-sdk/router';
9
9
 
10
10
  export default {
11
11
  external: new ExternalExecutorRouter()
@@ -13,8 +13,8 @@ export default {
13
13
  .useBearerAuthorization(['/api'])
14
14
  .useErrorHandling(async (e) => {
15
15
  console.error(e);
16
- if (e instanceof RpcError) {
17
- return new Response(null, { status: mapErrorToHttpError(e.code) });
16
+ if (e instanceof ConnectError) {
17
+ return new Response(null, { status: mapConnectErrorToHttpStatus(e) });
18
18
  }
19
19
  return new Response(null, {
20
20
  status: 500,
@@ -23,12 +23,15 @@ export default {
23
23
  })
24
24
  .add('POST', '/api/done', async (req, api, _route, ctx) => {
25
25
  const sapi = api.getSessionApi(req.headers.get('Authorization')!);
26
- ctx.waitUntil(sapi.complete('output', {}));
26
+ ctx.waitUntil(sapi.send('output', {}));
27
27
  return new Response();
28
28
  })
29
- .add('GET', '{*any}', async () => {
30
- return new Response(EXECUTOR_INDEX_HTML['___VERTEX_NAME___'], {
31
- headers: { 'Content-Type': 'text/html' }
29
+ .add('GET', '{/*any}', async (_, api) => {
30
+ const res = await api.readFile(
31
+ 'browser/___VERTEX_NAME___/executor.html'
32
+ );
33
+ return new Response(res.content, {
34
+ headers: { 'Content-Type': 'text/html; charset=utf-8' }
32
35
  });
33
36
  }),
34
37
  internal: new InternalExecutorRouter()
@@ -40,12 +43,8 @@ export default {
40
43
  console.log('Stop has been called');
41
44
  console.log(stop);
42
45
  })
43
- .onStream(async (res, _api, name) => {
44
- console.log(`Stream ${name} has been called`);
45
- console.log(res);
46
- })
47
- .onProcedure(async (res, _api, name) => {
48
- console.log(`Procedure ${name} has been called`);
46
+ .onExchange(async (res, _api, name) => {
47
+ console.log(`Exchange ${name} has been called`);
49
48
  console.log(res);
50
49
  })
51
50
  };