@mochabug/adaptkit 1.0.0-beta.9 → 1.0.0-rc.12

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 (83) hide show
  1. package/assets/build.js +2 -57
  2. package/assets/configurator.html +14 -0
  3. package/assets/configurator.ssg.tsx +2 -16
  4. package/assets/configurator_none.ts +4 -4
  5. package/assets/configurator_react.tsx +10 -7
  6. package/assets/executor.html +14 -0
  7. package/assets/executor.ssg.tsx +2 -16
  8. package/assets/executor_action.ts +3 -7
  9. package/assets/{executor_cron_trigger.ts → executor_action_cron.ts} +3 -7
  10. package/assets/executor_browser_none.ts +8 -12
  11. package/assets/executor_browser_none_cron.ts +119 -0
  12. package/assets/executor_browser_react.tsx +14 -15
  13. package/assets/executor_browser_react_cron.tsx +55 -0
  14. package/assets/{executor_external_trigger.ts → executor_external.ts} +7 -11
  15. package/assets/executor_external_cron.ts +45 -0
  16. package/assets/gitignore +3 -1
  17. package/assets/tsconf.json +3 -5
  18. package/bin/add.d.ts +3 -0
  19. package/bin/add.d.ts.map +1 -0
  20. package/bin/genproto/buf/validate/validate_pb.d.ts +8122 -0
  21. package/bin/genproto/buf/validate/validate_pb.d.ts.map +1 -0
  22. package/bin/genproto/google/api/annotations_pb.d.ts +14 -0
  23. package/bin/genproto/google/api/annotations_pb.d.ts.map +1 -0
  24. package/bin/genproto/google/api/client_pb.d.ts +1402 -0
  25. package/bin/genproto/google/api/client_pb.d.ts.map +1 -0
  26. package/bin/genproto/google/api/http_pb.d.ts +837 -0
  27. package/bin/genproto/google/api/http_pb.d.ts.map +1 -0
  28. package/bin/genproto/google/api/launch_stage_pb.d.ts +94 -0
  29. package/bin/genproto/google/api/launch_stage_pb.d.ts.map +1 -0
  30. package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts +75 -0
  31. package/bin/genproto/mochabugapis/adapt/graph/exchange_pb.d.ts.map +1 -0
  32. package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts +225 -0
  33. package/bin/genproto/mochabugapis/adapt/graph/jtd_schema_pb.d.ts.map +1 -0
  34. package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts +67 -0
  35. package/bin/genproto/mochabugapis/adapt/graph/receiver_pb.d.ts.map +1 -0
  36. package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts +133 -0
  37. package/bin/genproto/mochabugapis/adapt/graph/signal_binding_pb.d.ts.map +1 -0
  38. package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts +87 -0
  39. package/bin/genproto/mochabugapis/adapt/graph/signal_descriptor_pb.d.ts.map +1 -0
  40. package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts +75 -0
  41. package/bin/genproto/mochabugapis/adapt/graph/transceiver_pb.d.ts.map +1 -0
  42. package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts +118 -0
  43. package/bin/genproto/mochabugapis/adapt/graph/transmitter_pb.d.ts.map +1 -0
  44. package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts +97 -0
  45. package/bin/genproto/mochabugapis/adapt/graph/vertex_metadata_pb.d.ts.map +1 -0
  46. package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts +62 -0
  47. package/bin/genproto/mochabugapis/adapt/plugins/v1/file_pb.d.ts.map +1 -0
  48. package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts +223 -0
  49. package/bin/genproto/mochabugapis/adapt/plugins/v1/manifest_pb.d.ts.map +1 -0
  50. package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts +715 -0
  51. package/bin/genproto/mochabugapis/adapt/plugins/v1/oauth2_service_pb.d.ts.map +1 -0
  52. package/bin/genproto/mochabugapis/adapt/plugins/v1/oneof_service_pb.d.ts +92 -0
  53. package/bin/genproto/mochabugapis/adapt/plugins/v1/oneof_service_pb.d.ts.map +1 -0
  54. package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts +194 -0
  55. package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins_pb.d.ts.map +1 -0
  56. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_binding_pb.d.ts +134 -0
  57. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_binding_pb.d.ts.map +1 -0
  58. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts +116 -0
  59. package/bin/genproto/mochabugapis/adapt/plugins/v1/service_definition_pb.d.ts.map +1 -0
  60. package/bin/genproto/mochabugapis/adapt/plugins/v1/tls_service_pb.d.ts +159 -0
  61. package/bin/genproto/mochabugapis/adapt/plugins/v1/tls_service_pb.d.ts.map +1 -0
  62. package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts +60 -0
  63. package/bin/genproto/mochabugapis/adapt/plugins/v1/variable_service_pb.d.ts.map +1 -0
  64. package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts +224 -0
  65. package/bin/genproto/mochabugapis/adapt/plugins/v1/vertex_pb.d.ts.map +1 -0
  66. package/bin/index.d.ts +7 -0
  67. package/bin/index.d.ts.map +1 -0
  68. package/bin/index.js +5937 -27
  69. package/bin/index.js.map +4 -4
  70. package/bin/init.d.ts +2 -0
  71. package/bin/init.d.ts.map +1 -0
  72. package/bin/oauth2.d.ts +2 -0
  73. package/bin/oauth2.d.ts.map +1 -0
  74. package/bin/publish.d.ts +23 -0
  75. package/bin/publish.d.ts.map +1 -0
  76. package/bin/utils.d.ts +13 -0
  77. package/bin/utils.d.ts.map +1 -0
  78. package/bin/vertices.d.ts +3 -0
  79. package/bin/vertices.d.ts.map +1 -0
  80. package/package.json +15 -22
  81. package/assets/build-client.js +0 -107
  82. package/assets/global.d.ts +0 -7
  83. package/assets/inject.js +0 -15
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-plugin-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,6 +1,6 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus
4
4
  } from '@mochabug/adapt-plugin-toolkit/api';
5
5
  import {
6
6
  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,
@@ -1,6 +1,6 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus
4
4
  } from '@mochabug/adapt-plugin-toolkit/api';
5
5
  import {
6
6
  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,
@@ -29,9 +29,12 @@ export default {
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
  }
@@ -5,18 +5,14 @@ export default {
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
  };
@@ -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,7 +1,7 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-plugin-toolkit/api";
5
5
  import {
6
6
  ExternalExecutorRouter,
7
7
  InternalExecutorRouter
@@ -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-plugin-toolkit/api";
5
+ import {
6
+ ExternalExecutorRouter,
7
+ CronExecutorRouter
8
+ } from '@mochabug/adapt-plugin-toolkit/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,7 +1,7 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-plugin-toolkit/api";
5
5
  import {
6
6
  ExternalExecutorRouter,
7
7
  InternalExecutorRouter
@@ -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
  };
@@ -0,0 +1,55 @@
1
+ import {
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-plugin-toolkit/api";
5
+ import {
6
+ ExternalExecutorRouter,
7
+ CronExecutorRouter
8
+ } from '@mochabug/adapt-plugin-toolkit/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 (_, 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' }
35
+ });
36
+ }),
37
+ internal: new CronExecutorRouter()
38
+ .onStart(async (start, _api) => {
39
+ console.log('Start has been called');
40
+ console.log(start);
41
+ })
42
+ .onStop(async (stop, _api) => {
43
+ console.log('Stop has been called');
44
+ console.log(stop);
45
+ })
46
+ .onExchange(async (res, _api, name) => {
47
+ console.log(`Exchange ${name} has been called`);
48
+ console.log(res);
49
+ })
50
+ .onCron(async (cron, api, ctx) => {
51
+ console.log('Received cron event');
52
+ ctx.waitUntil(api.send('output', {}));
53
+ console.log(cron);
54
+ })
55
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
- mapErrorToHttpError,
3
- RpcError
4
- } from '@mochabug/adapt-plugin-toolkit/api';
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-plugin-toolkit/api";
5
5
  import {
6
6
  ExternalExecutorRouter,
7
7
  InternalExecutorRouter
@@ -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,
@@ -33,12 +33,8 @@ export default {
33
33
  console.log('Stop has been called');
34
34
  console.log(stop);
35
35
  })
36
- .onStream(async (res, _api, name) => {
37
- console.log(`Stream ${name} has been called`);
38
- console.log(res);
39
- })
40
- .onProcedure(async (res, _api, name) => {
41
- console.log(`Procedure ${name} has been called`);
36
+ .onExchange(async (res, _api, name) => {
37
+ console.log(`Exchange ${name} has been called`);
42
38
  console.log(res);
43
39
  })
44
40
  };
@@ -0,0 +1,45 @@
1
+ import {
2
+ ConnectError,
3
+ mapConnectErrorToHttpStatus,
4
+ } from "@mochabug/adapt-plugin-toolkit/api";
5
+ import {
6
+ ExternalExecutorRouter,
7
+ InternalExecutorRouter
8
+ } from '@mochabug/adapt-plugin-toolkit/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('*', '(.*)', async (_req, _api, _route, _ctx) => {
25
+ return new Response();
26
+ }),
27
+ internal: new InternalExecutorRouter()
28
+ .onStart(async (start, _api) => {
29
+ console.log('Start has been called');
30
+ console.log(start);
31
+ })
32
+ .onStop(async (stop, _api) => {
33
+ console.log('Stop has been called');
34
+ console.log(stop);
35
+ })
36
+ .onExchange(async (res, _api, name) => {
37
+ console.log(`Exchange ${name} has been called`);
38
+ console.log(res);
39
+ })
40
+ .onCron(async (cron, api, ctx) => {
41
+ console.log('Received cron event');
42
+ ctx.waitUntil(api.send('output', {}));
43
+ console.log(cron);
44
+ })
45
+ };
package/assets/gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  # Cdn files
2
- cdn/**
2
+ cdn/browser
3
+ assets/browser
4
+ dist/
3
5
 
4
6
  # Logs
5
7
  logs
@@ -33,10 +33,8 @@
33
33
  },
34
34
  "exclude": [
35
35
  "dist/**",
36
- "cdn/**",
37
- "assets/**",
38
- "build.js",
39
- "inject.js",
40
- "build-client.js"
36
+ "cdn/browser/**",
37
+ "assets/browser/**",
38
+ "build.js"
41
39
  ],
42
40
  }
package/bin/add.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Manifest } from './genproto/mochabugapis/adapt/plugins/v1/manifest_pb';
2
+ export declare function add(manifest: Manifest): Promise<void>;
3
+ //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../src/add.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sDAAsD,CAAC;AAIhF,wBAAsB,GAAG,CAAC,QAAQ,EAAE,QAAQ,iBA2E3C"}