@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.
- package/README.md +50 -45
- package/assets/build.js +2 -57
- package/assets/configurator.html +14 -0
- package/assets/configurator.ssg.tsx +2 -16
- package/assets/configurator_none.ts +8 -8
- package/assets/configurator_react.tsx +14 -11
- package/assets/executor.html +14 -0
- package/assets/executor.ssg.tsx +2 -16
- package/assets/executor_action.ts +4 -8
- package/assets/{executor_cron_trigger.ts → executor_action_cron.ts} +4 -8
- package/assets/executor_browser_none.ts +9 -13
- package/assets/executor_browser_none_cron.ts +119 -0
- package/assets/executor_browser_react.tsx +15 -16
- package/assets/executor_browser_react_cron.tsx +55 -0
- package/assets/{executor_external_trigger.ts → executor_external.ts} +8 -12
- package/assets/executor_external_cron.ts +45 -0
- package/assets/gitignore +3 -1
- package/assets/tsconf.json +4 -7
- package/bin/add.d.ts +3 -0
- package/bin/add.d.ts.map +1 -0
- package/bin/genproto/buf/validate/validate_pb.d.ts +8491 -0
- package/bin/genproto/buf/validate/validate_pb.d.ts.map +1 -0
- package/bin/genproto/google/api/annotations_pb.d.ts +14 -0
- package/bin/genproto/google/api/annotations_pb.d.ts.map +1 -0
- package/bin/genproto/google/api/client_pb.d.ts +1432 -0
- package/bin/genproto/google/api/client_pb.d.ts.map +1 -0
- package/bin/genproto/google/api/http_pb.d.ts +843 -0
- package/bin/genproto/google/api/http_pb.d.ts.map +1 -0
- package/bin/genproto/google/api/launch_stage_pb.d.ts +94 -0
- package/bin/genproto/google/api/launch_stage_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts +77 -0
- package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts +401 -0
- package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts +69 -0
- package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts +430 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_data_pb.d.ts +198 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_data_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts +161 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_format_pb.d.ts +305 -0
- package/bin/genproto/mochabugapis/adapt/graph/signal_format_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts +77 -0
- package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts +120 -0
- package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts +99 -0
- package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/compound_services_pb.d.ts +347 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/compound_services_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts +64 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/http_proxy_service_pb.d.ts +1282 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/http_proxy_service_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts +388 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts +805 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts +238 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts +241 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/service_settings_pb.d.ts +539 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/service_settings_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts +190 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts +269 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts.map +1 -0
- package/bin/index.d.ts +12 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +846 -711
- package/bin/index.js.map +4 -4
- package/bin/init.d.ts +2 -0
- package/bin/init.d.ts.map +1 -0
- package/bin/oauth2.d.ts +2 -0
- package/bin/oauth2.d.ts.map +1 -0
- package/bin/publish.d.ts +27 -0
- package/bin/publish.d.ts.map +1 -0
- package/bin/utils.d.ts +13 -0
- package/bin/utils.d.ts.map +1 -0
- package/bin/vertices.d.ts +3 -0
- package/bin/vertices.d.ts.map +1 -0
- package/package.json +25 -27
- package/assets/build-client.js +0 -111
- package/assets/global.d.ts +0 -7
- package/assets/inject.js +0 -15
- package/assets/license.md +0 -15
package/README.md
CHANGED
|
@@ -1,82 +1,87 @@
|
|
|
1
|
-
# @mochabug/adaptkit
|
|
1
|
+
# @mochabug/adaptkit
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
+
## Plugin Architecture
|
|
13
14
|
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
+
### Configurator (Optional)
|
|
25
|
+
Provides UI for customizing executor behavior on the Mochabug Adapt platform.
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
## Installation
|
|
25
28
|
|
|
26
29
|
```bash
|
|
27
30
|
npm install -g @mochabug/adaptkit
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
##
|
|
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
|
|
37
|
+
adaptkit init
|
|
38
38
|
```
|
|
39
|
+
Creates a new plugin with `manifest.json`, executor/configurator templates, and schema files.
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
2. **Emulate your plugins in the cloud environment**
|
|
43
|
-
|
|
41
|
+
### Add Vertices to Your Plugin
|
|
44
42
|
```bash
|
|
45
|
-
adaptkit
|
|
43
|
+
adaptkit add
|
|
46
44
|
```
|
|
45
|
+
Interactively adds new vertices to your existing plugin project.
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
|
61
|
+
adaptkit publish
|
|
62
62
|
```
|
|
63
|
+
Deploy your plugin to the Mochabug Adapt platform for production use.
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
4. **Publish your plugin to the Mochabug Adapt platform**
|
|
67
|
-
|
|
65
|
+
### Version Management
|
|
68
66
|
```bash
|
|
69
|
-
adaptkit --
|
|
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
|
-
|
|
77
|
+
## Documentation
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
For comprehensive documentation and API references, visit [Mochabug Developer Portal](https://developers.mochabug.com).
|
|
75
80
|
|
|
76
|
-
|
|
81
|
+
## Contributing
|
|
77
82
|
|
|
78
|
-
|
|
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
|
-
|
|
85
|
+
## License
|
|
81
86
|
|
|
82
|
-
|
|
87
|
+
Apache License 2.0
|
package/assets/build.js
CHANGED
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 (
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
} from '@mochabug/adapt-
|
|
2
|
+
ConnectError,
|
|
3
|
+
mapConnectErrorToHttpStatus
|
|
4
|
+
} from '@mochabug/adapt-sdk/api';
|
|
5
5
|
import {
|
|
6
6
|
ExternalConfiguratorRouter,
|
|
7
7
|
InternalConfiguratorRouter
|
|
8
|
-
} from '@mochabug/adapt-
|
|
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
|
|
17
|
-
return new Response(null, { status:
|
|
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
|
|
26
|
-
return new Response(JSON.stringify(
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
} from '@mochabug/adapt-
|
|
2
|
+
ConnectError,
|
|
3
|
+
mapConnectErrorToHttpStatus
|
|
4
|
+
} from '@mochabug/adapt-sdk/api';
|
|
5
5
|
import {
|
|
6
6
|
ExternalConfiguratorRouter,
|
|
7
7
|
InternalConfiguratorRouter
|
|
8
|
-
} from '@mochabug/adapt-
|
|
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
|
|
17
|
-
return new Response(null, { status:
|
|
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
|
|
26
|
-
return new Response(JSON.stringify(
|
|
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', '{
|
|
33
|
-
|
|
34
|
-
|
|
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>
|
package/assets/executor.ssg.tsx
CHANGED
|
@@ -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 (
|
|
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-
|
|
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.
|
|
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
|
-
.
|
|
15
|
-
console.log(`
|
|
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-
|
|
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
|
-
.
|
|
14
|
-
console.log(`
|
|
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.
|
|
19
|
+
ctx.waitUntil(api.send('output', {}));
|
|
24
20
|
console.log(cron);
|
|
25
21
|
})
|
|
26
22
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
2
|
+
ConnectError,
|
|
3
|
+
mapConnectErrorToHttpStatus,
|
|
4
|
+
} from "@mochabug/adapt-sdk/api";
|
|
5
5
|
import {
|
|
6
6
|
ExternalExecutorRouter,
|
|
7
7
|
InternalExecutorRouter
|
|
8
|
-
} from '@mochabug/adapt-
|
|
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
|
|
17
|
-
return new Response(null, { status:
|
|
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.
|
|
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
|
-
.
|
|
46
|
-
console.log(`
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
2
|
+
ConnectError,
|
|
3
|
+
mapConnectErrorToHttpStatus,
|
|
4
|
+
} from "@mochabug/adapt-sdk/api";
|
|
5
5
|
import {
|
|
6
6
|
ExternalExecutorRouter,
|
|
7
7
|
InternalExecutorRouter
|
|
8
|
-
} from '@mochabug/adapt-
|
|
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
|
|
17
|
-
return new Response(null, { status:
|
|
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.
|
|
26
|
+
ctx.waitUntil(sapi.send('output', {}));
|
|
27
27
|
return new Response();
|
|
28
28
|
})
|
|
29
|
-
.add('GET', '{
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
.
|
|
44
|
-
console.log(`
|
|
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
|
};
|