@versori/run 0.1.0-alpha.11 → 0.1.0-alpha.13
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/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.d.ts +3 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.d.ts.map +1 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.js +28 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +35 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +328 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.d.ts +3 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.js +2 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.d.ts +2 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.d.ts.map +1 -0
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts +21 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.js +32 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts +41 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/copy.js +50 -0
- package/{script/deps/jsr.io/@std/fmt/1.0.6 → esm/deps/jsr.io/@std/fmt/1.0.5}/colors.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/io/0.225.2/_common.d.ts +3 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/_common.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/_common.js +8 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/_constants.d.ts +3 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/_constants.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/_constants.js +4 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/buffer.d.ts +321 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/buffer.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/buffer.js +488 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/copy.d.ts +25 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/copy.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/copy.js +36 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/iterate_reader.d.ts +80 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/iterate_reader.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/iterate_reader.js +96 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/mod.d.ts +25 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/mod.js +25 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/read_all.d.ts +42 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/read_all.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/read_all.js +72 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.d.ts +20 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.js +36 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_readable_stream.d.ts +40 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_readable_stream.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_readable_stream.js +54 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_writable_stream.d.ts +27 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_writable_stream.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.2/to_writable_stream.js +44 -0
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +21 -0
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +1 -1
- package/esm/src/context/Context.d.ts +14 -4
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +16 -10
- package/esm/src/context/ContextProvider.d.ts +3 -4
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +5 -5
- package/esm/src/dsl/http/versori/platformapi.d.ts +2 -1
- package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/platformapi.js +12 -1
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +32 -35
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +6 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +67 -5
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +106 -32
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts +2 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.js +1 -1
- package/package.json +2 -1
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.d.ts +3 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.d.ts.map +1 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.js +31 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +35 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +333 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.d.ts +3 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.js +20 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.d.ts +2 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.d.ts.map +1 -0
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/version.js +5 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +3 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts +21 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +35 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts +41 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/copy.js +53 -0
- package/{esm/deps/jsr.io/@std/fmt/1.0.6 → script/deps/jsr.io/@std/fmt/1.0.5}/colors.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/io/0.225.2/_common.d.ts +3 -0
- package/script/deps/jsr.io/@std/io/0.225.2/_common.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/_common.js +11 -0
- package/script/deps/jsr.io/@std/io/0.225.2/_constants.d.ts +3 -0
- package/script/deps/jsr.io/@std/io/0.225.2/_constants.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/_constants.js +7 -0
- package/script/deps/jsr.io/@std/io/0.225.2/buffer.d.ts +321 -0
- package/script/deps/jsr.io/@std/io/0.225.2/buffer.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/buffer.js +492 -0
- package/script/deps/jsr.io/@std/io/0.225.2/copy.d.ts +25 -0
- package/script/deps/jsr.io/@std/io/0.225.2/copy.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/copy.js +39 -0
- package/script/deps/jsr.io/@std/io/0.225.2/iterate_reader.d.ts +80 -0
- package/script/deps/jsr.io/@std/io/0.225.2/iterate_reader.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/iterate_reader.js +100 -0
- package/script/deps/jsr.io/@std/io/0.225.2/mod.d.ts +25 -0
- package/script/deps/jsr.io/@std/io/0.225.2/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/mod.js +41 -0
- package/script/deps/jsr.io/@std/io/0.225.2/read_all.d.ts +42 -0
- package/script/deps/jsr.io/@std/io/0.225.2/read_all.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/read_all.js +76 -0
- package/script/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.d.ts +20 -0
- package/script/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/reader_from_stream_reader.js +39 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_readable_stream.d.ts +40 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_readable_stream.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_readable_stream.js +57 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_writable_stream.d.ts +27 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_writable_stream.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.2/to_writable_stream.js +47 -0
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +21 -0
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +1 -1
- package/script/src/context/Context.d.ts +14 -4
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +16 -10
- package/script/src/context/ContextProvider.d.ts +3 -4
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +5 -5
- package/script/src/dsl/http/versori/platformapi.d.ts +2 -1
- package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/platformapi.js +12 -1
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +32 -35
- package/script/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +6 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +67 -5
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +109 -32
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts +2 -1
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.js +3 -3
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.5}/colors.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.5}/colors.js +0 -0
- /package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.js +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.5}/colors.d.ts +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.5}/colors.js +0 -0
- /package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.d.ts +0 -0
- /package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.11}/exists.js +0 -0
|
@@ -1,71 +1,136 @@
|
|
|
1
1
|
// In src/interpreter/memory/compilers/webhook.ts
|
|
2
|
+
import cors from 'cors';
|
|
2
3
|
import { Observable } from 'rxjs';
|
|
4
|
+
import { pipeline } from "node:stream/promises";
|
|
3
5
|
import { WebhookTrigger } from '../../../dsl/triggers/WebhookTrigger.js';
|
|
6
|
+
const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), { status: 200 });
|
|
7
|
+
const DEFAULT_SYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({ message: 'Internal server error', error: ctx.data }), {
|
|
8
|
+
status: 500,
|
|
9
|
+
});
|
|
10
|
+
const DEFAULT_ASYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify({
|
|
11
|
+
status: 'accepted',
|
|
12
|
+
executionId: ctx.executionId,
|
|
13
|
+
startTime: ctx.startTime,
|
|
14
|
+
}), { status: 202 });
|
|
15
|
+
const DEFAULT_ASYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({
|
|
16
|
+
message: 'Internal server error',
|
|
17
|
+
executionId: ctx.executionId,
|
|
18
|
+
startTime: ctx.startTime,
|
|
19
|
+
}), {
|
|
20
|
+
status: 500,
|
|
21
|
+
});
|
|
4
22
|
export const webhookCompiler = {
|
|
5
23
|
ctor: WebhookTrigger,
|
|
6
24
|
compile: (ctx, trigger, signal) => {
|
|
25
|
+
const { response: { mode = 'async', } = {}, cors: corsOptions, } = trigger.options;
|
|
26
|
+
const isSync = mode === 'sync';
|
|
27
|
+
const isAsync = mode === 'async';
|
|
28
|
+
if (!isSync && !isAsync) {
|
|
29
|
+
throw new Error('Invalid response mode, must be either "sync" or "async"');
|
|
30
|
+
}
|
|
31
|
+
let onSuccess = isSync ? DEFAULT_SYNC_ON_SUCCESS : DEFAULT_ASYNC_ON_SUCCESS;
|
|
32
|
+
let onError = isSync ? DEFAULT_SYNC_ON_ERROR : DEFAULT_ASYNC_ON_ERROR;
|
|
33
|
+
if (trigger.options.response?.onSuccess) {
|
|
34
|
+
onSuccess = trigger.options.response.onSuccess;
|
|
35
|
+
}
|
|
36
|
+
if (trigger.options.response?.onError) {
|
|
37
|
+
onError = trigger.options.response.onError;
|
|
38
|
+
}
|
|
39
|
+
const ctxOptionsFn = (res) => ({
|
|
40
|
+
onSuccess: (ctx) => {
|
|
41
|
+
if (isSync) {
|
|
42
|
+
sendResponse(res, onSuccess(ctx));
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onError: (ctx) => {
|
|
46
|
+
if (isSync) {
|
|
47
|
+
sendResponse(res, onError(ctx));
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
7
51
|
return new Observable((subscriber) => {
|
|
8
52
|
if (!ctx.router) {
|
|
9
53
|
throw new Error('Router not available in compiler context');
|
|
10
54
|
}
|
|
11
55
|
// add the webhook endpoint to the router
|
|
12
56
|
ctx.log.info('webhook endpoint added:', { trigger });
|
|
57
|
+
if (corsOptions) {
|
|
58
|
+
if (typeof corsOptions === 'boolean') {
|
|
59
|
+
ctx.router.use(cors());
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
ctx.router.use(cors(corsOptions));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
13
65
|
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
14
66
|
ctx.router.post(`/${trigger.id}`, (req, res) => {
|
|
15
|
-
const executionCtx = ctx.contextProvider.create(req.body,
|
|
67
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
16
68
|
try {
|
|
17
69
|
subscriber.next(executionCtx);
|
|
18
|
-
|
|
70
|
+
if (isAsync) {
|
|
71
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
72
|
+
}
|
|
19
73
|
}
|
|
20
74
|
catch (error) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
75
|
+
executionCtx.log.error('webhook execution error', {
|
|
76
|
+
error: JSON.stringify(error),
|
|
77
|
+
});
|
|
78
|
+
if (isAsync) {
|
|
79
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
80
|
+
}
|
|
24
81
|
}
|
|
25
82
|
});
|
|
26
83
|
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
27
84
|
ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
|
|
28
|
-
const userId = req.params.userId
|
|
29
|
-
if (!userId) {
|
|
30
|
-
res.status(400).json({ status: 'error', message: 'User ID is required' });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
85
|
+
const userId = req.params.userId;
|
|
33
86
|
const activations = await ctx.connectionProvider.getUserActivations(userId);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
87
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
88
|
+
const errors = [];
|
|
38
89
|
activations.forEach((activation) => {
|
|
39
|
-
const
|
|
90
|
+
const activationCtx = executionCtx.withActivation(activation);
|
|
40
91
|
try {
|
|
41
|
-
subscriber.next(
|
|
92
|
+
subscriber.next(activationCtx);
|
|
42
93
|
}
|
|
43
94
|
catch (error) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
95
|
+
activationCtx.log.error('webhook execution error', {
|
|
96
|
+
error: JSON.stringify(error),
|
|
97
|
+
});
|
|
98
|
+
errors.push({
|
|
99
|
+
activationId: activation.id,
|
|
100
|
+
error,
|
|
101
|
+
});
|
|
47
102
|
}
|
|
48
103
|
});
|
|
49
|
-
|
|
104
|
+
if (isAsync) {
|
|
105
|
+
if (errors.length === 0) {
|
|
106
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
50
112
|
});
|
|
51
113
|
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
52
114
|
ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
53
|
-
const activationId = req.params.activationId
|
|
115
|
+
const activationId = req.params.activationId;
|
|
54
116
|
const activation = await ctx.connectionProvider.getActivation(activationId);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const executionCtx = ctx.contextProvider.create(req.body, activation);
|
|
117
|
+
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
118
|
+
...ctxOptionsFn(res),
|
|
119
|
+
activation,
|
|
120
|
+
});
|
|
61
121
|
try {
|
|
62
|
-
subscriber.next(
|
|
63
|
-
|
|
122
|
+
subscriber.next(activationCtx);
|
|
123
|
+
if (isAsync) {
|
|
124
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
125
|
+
}
|
|
64
126
|
}
|
|
65
127
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
128
|
+
activationCtx.log.error('webhook execution error', {
|
|
129
|
+
error: JSON.stringify(error),
|
|
130
|
+
});
|
|
131
|
+
if (isAsync) {
|
|
132
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
133
|
+
}
|
|
69
134
|
}
|
|
70
135
|
});
|
|
71
136
|
function cleanup() {
|
|
@@ -80,3 +145,12 @@ export const webhookCompiler = {
|
|
|
80
145
|
});
|
|
81
146
|
},
|
|
82
147
|
};
|
|
148
|
+
function sendResponse(res, response) {
|
|
149
|
+
res.status(response.status);
|
|
150
|
+
response.headers.forEach((value, key) => {
|
|
151
|
+
res.setHeader(key, value);
|
|
152
|
+
});
|
|
153
|
+
if (response.body) {
|
|
154
|
+
pipeline(response.body, res);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TlsOptions } from '
|
|
1
|
+
import { TlsOptions } from '../../../deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.js';
|
|
2
2
|
import { DestroyOptions, KeyValue, KeyValueProvider, KVOptions } from '../KeyValue.js';
|
|
3
3
|
export type NatsKeyValueProviderOptions = {
|
|
4
4
|
organizationId: string;
|
|
@@ -19,6 +19,7 @@ export declare class NatsKeyValueProvider implements KeyValueProvider, AsyncDisp
|
|
|
19
19
|
private constructor();
|
|
20
20
|
static newInstance(opts?: Partial<NatsKeyValueProviderOptions>): Promise<NatsKeyValueProvider>;
|
|
21
21
|
static fromEnv(): Promise<NatsKeyValueProvider>;
|
|
22
|
+
[Symbol.asyncDispose](): PromiseLike<void>;
|
|
22
23
|
kv(options: KVOptions): KeyValue;
|
|
23
24
|
destroy(options: DestroyOptions): Promise<void>;
|
|
24
25
|
private subjectPrefix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,UAAU,EAAE,MAAM,+DAA+D,CAAC;AACxH,OAAO,EACH,cAAc,EAEd,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACZ,MAAM,gBAAgB,CAAC;AA4CxB,MAAM,MAAM,2BAA2B,GAAG;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QACF,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,CAAC,EAAE,UAAU,CAAC;KACpB,CAAC;CACL,CAAC;AAuBF,qBAAa,oBAAqB,YAAW,gBAAgB,EAAE,eAAe;IAEtE,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IALzB,OAAO;WAQM,WAAW,CACpB,IAAI,GAAE,OAAO,CAAC,2BAA2B,CAAM,GAChD,OAAO,CAAC,oBAAoB,CAAC;IA0BhC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAI/C,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC;IAI1C,EAAE,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ;IAqB1B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBrD,OAAO,CAAC,aAAa;CAYxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JetStreamApiCodes, JetStreamApiError } from '../../../deps/jsr.io/@nats-io/jetstream/3.0.2/src/mod.js';
|
|
2
2
|
import { Kvm } from '../../../deps/jsr.io/@nats-io/kv/3.0.2/src/mod.js';
|
|
3
|
-
import { connect, credsAuthenticator } from '
|
|
3
|
+
import { connect, credsAuthenticator } from '../../../deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.js';
|
|
4
4
|
import { isKVOptionsExecution, } from '../KeyValue.js';
|
|
5
5
|
import { NatsKeyValue } from './NatsKeyValue.js';
|
|
6
6
|
function getOptionsFromEnv() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versori/run",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "0.1.0-alpha.13",
|
|
4
4
|
"description": "Versori Run",
|
|
5
5
|
"homepage": "https://github.com/versori/versori-run#readme",
|
|
6
6
|
"repository": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@connectrpc/connect-node": "^2.0.1",
|
|
29
29
|
"cron": "3.5.0",
|
|
30
30
|
"express": "^4.18.3",
|
|
31
|
+
"lru-cache": "^11.0.2",
|
|
31
32
|
"rxjs": "^7.8.1",
|
|
32
33
|
"tweetnacl": "1.0.3"
|
|
33
34
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/connect.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EAGf,MAAM,8CAA8C,CAAC;AAStD,wBAAgB,OAAO,CAAC,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiB7E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connect = connect;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020-2024 The NATS Authors
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
const deno_transport_js_1 = require("./deno_transport.js");
|
|
19
|
+
const internal_mod_js_1 = require("../../../nats-core/3.0.2/src/internal_mod.js");
|
|
20
|
+
function connect(opts = {}) {
|
|
21
|
+
if ((0, internal_mod_js_1.hasWsProtocol)(opts)) {
|
|
22
|
+
return Promise.reject(internal_mod_js_1.errors.InvalidArgumentError.format(`servers`, `deno client doesn't support websockets, use the 'wsconnect' function instead`));
|
|
23
|
+
}
|
|
24
|
+
(0, internal_mod_js_1.setTransportFactory)({
|
|
25
|
+
factory: () => {
|
|
26
|
+
return new deno_transport_js_1.DenoTransport();
|
|
27
|
+
},
|
|
28
|
+
dnsResolveFn: deno_transport_js_1.denoResolveHost,
|
|
29
|
+
});
|
|
30
|
+
return internal_mod_js_1.NatsConnectionImpl.connect(opts);
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ConnectionOptions, ServerInfo, Transport } from "../../../nats-core/3.0.2/src/internal_mod.js";
|
|
2
|
+
export declare class DenoTransport implements Transport {
|
|
3
|
+
version: string;
|
|
4
|
+
lang: string;
|
|
5
|
+
closeError?: Error;
|
|
6
|
+
private options;
|
|
7
|
+
private buf;
|
|
8
|
+
private encrypted;
|
|
9
|
+
private done;
|
|
10
|
+
private closedNotification;
|
|
11
|
+
private conn;
|
|
12
|
+
private frames;
|
|
13
|
+
private pendingWrite;
|
|
14
|
+
constructor();
|
|
15
|
+
connect(hp: {
|
|
16
|
+
hostname: string;
|
|
17
|
+
port: number;
|
|
18
|
+
tlsName: string;
|
|
19
|
+
}, options: ConnectionOptions): Promise<void>;
|
|
20
|
+
get isClosed(): boolean;
|
|
21
|
+
peekInfo(): Promise<ServerInfo>;
|
|
22
|
+
loadTlsOptions(hostname: string): Promise<Deno.StartTlsOptions>;
|
|
23
|
+
startTLS(hostname: string): Promise<void>;
|
|
24
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
|
|
25
|
+
maybeWriteFrame(): void;
|
|
26
|
+
send(frame: Uint8Array): void;
|
|
27
|
+
isEncrypted(): boolean;
|
|
28
|
+
close(err?: Error): Promise<void>;
|
|
29
|
+
disconnect(): void;
|
|
30
|
+
_closed(err?: Error, internal?: boolean): Promise<void>;
|
|
31
|
+
closed(): Promise<void | Error>;
|
|
32
|
+
discard(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function denoResolveHost(s: string): Promise<string[]>;
|
|
35
|
+
//# sourceMappingURL=deno_transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno_transport.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EACV,iBAAiB,EAEjB,UAAU,EAEV,SAAS,EACV,MAAM,8CAA8C,CAAC;AAUtD,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,EAAE,MAAM,CAAW;IAC1B,IAAI,EAAE,MAAM,CAAQ;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,kBAAkB,CAAsC;IAChE,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,YAAY,CAAuB;;IAQrC,OAAO,CACX,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EACvD,OAAO,EAAE,iBAAiB;IA4C5B,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAEK,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC;IAgC/B,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC;IAoB/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,UAAU,CAAC;IA2BlE,eAAe,IAAI,IAAI;IAuBvB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAU7B,WAAW,IAAI,OAAO;IAItB,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,UAAU;IAKJ,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC1D,MAAM,IAAI,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;IAI/B,OAAO;CAGR;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAelE"}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-2024 The NATS Authors
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DenoTransport = void 0;
|
|
18
|
+
exports.denoResolveHost = denoResolveHost;
|
|
19
|
+
const internal_mod_js_1 = require("../../../nats-core/3.0.2/src/internal_mod.js");
|
|
20
|
+
const mod_js_1 = require("../../../../@std/io/0.225.2/mod.js");
|
|
21
|
+
const version_js_1 = require("./version.js");
|
|
22
|
+
const VERSION = version_js_1.version;
|
|
23
|
+
const LANG = "nats.deno";
|
|
24
|
+
const ReadBufferSize = 1024 * 256;
|
|
25
|
+
class DenoTransport {
|
|
26
|
+
constructor() {
|
|
27
|
+
Object.defineProperty(this, "version", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: VERSION
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "lang", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: LANG
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "closeError", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "options", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "buf", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(this, "encrypted", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: false
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(this, "done", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: false
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "closedNotification", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: (0, internal_mod_js_1.deferred)()
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "conn", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "frames", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "pendingWrite", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
93
|
+
this.buf = new Uint8Array(ReadBufferSize);
|
|
94
|
+
this.frames = [];
|
|
95
|
+
this.pendingWrite = null;
|
|
96
|
+
}
|
|
97
|
+
async connect(hp, options) {
|
|
98
|
+
this.options = options;
|
|
99
|
+
const { tls } = this.options;
|
|
100
|
+
const { handshakeFirst } = tls || {};
|
|
101
|
+
try {
|
|
102
|
+
if (handshakeFirst === true) {
|
|
103
|
+
const opts = await this.loadTlsOptions(hp.hostname);
|
|
104
|
+
const ctls = {
|
|
105
|
+
caCerts: opts.caCerts,
|
|
106
|
+
hostname: hp.hostname,
|
|
107
|
+
port: hp.port,
|
|
108
|
+
};
|
|
109
|
+
this.conn = await Deno.connectTls(ctls);
|
|
110
|
+
this.encrypted = true;
|
|
111
|
+
// do nothing yet.
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.conn = await Deno.connect(hp);
|
|
115
|
+
}
|
|
116
|
+
if (this.done) {
|
|
117
|
+
this.conn.close();
|
|
118
|
+
}
|
|
119
|
+
const info = await this.peekInfo();
|
|
120
|
+
(0, internal_mod_js_1.checkOptions)(info, this.options);
|
|
121
|
+
const { tls_required: tlsRequired, tls_available: tlsAvailable } = info;
|
|
122
|
+
const desired = tlsAvailable === true && options.tls !== null;
|
|
123
|
+
if (!handshakeFirst && (tlsRequired || desired)) {
|
|
124
|
+
const tlsn = hp.tlsName ? hp.tlsName : hp.hostname;
|
|
125
|
+
await this.startTLS(tlsn);
|
|
126
|
+
}
|
|
127
|
+
if (this.done) {
|
|
128
|
+
this.conn.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.conn?.close();
|
|
133
|
+
const _err = err;
|
|
134
|
+
throw new internal_mod_js_1.errors.ConnectionError(_err.message.toLowerCase(), {
|
|
135
|
+
cause: err,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
get isClosed() {
|
|
140
|
+
return this.done;
|
|
141
|
+
}
|
|
142
|
+
async peekInfo() {
|
|
143
|
+
const inbound = new internal_mod_js_1.DataBuffer();
|
|
144
|
+
let pm;
|
|
145
|
+
while (true) {
|
|
146
|
+
const c = await this.conn.read(this.buf);
|
|
147
|
+
if (c === null) {
|
|
148
|
+
// EOF
|
|
149
|
+
throw new Error("socket closed while expecting INFO");
|
|
150
|
+
}
|
|
151
|
+
else if (c) {
|
|
152
|
+
const frame = this.buf.subarray(0, c);
|
|
153
|
+
if (this.options.debug) {
|
|
154
|
+
console.info(`> ${(0, internal_mod_js_1.render)(frame)}`);
|
|
155
|
+
}
|
|
156
|
+
inbound.fill(frame);
|
|
157
|
+
const raw = inbound.peek();
|
|
158
|
+
pm = (0, internal_mod_js_1.extractProtocolMessage)(raw);
|
|
159
|
+
if (pm !== "") {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// reset the buffer to previously read, so the client
|
|
165
|
+
// can validate the info matches the connection
|
|
166
|
+
this.buf = new Uint8Array(inbound.drain());
|
|
167
|
+
// expecting the info protocol
|
|
168
|
+
const m = internal_mod_js_1.INFO.exec(pm);
|
|
169
|
+
if (!m) {
|
|
170
|
+
throw new Error("unexpected response from server");
|
|
171
|
+
}
|
|
172
|
+
return JSON.parse(m[1]);
|
|
173
|
+
}
|
|
174
|
+
async loadTlsOptions(hostname) {
|
|
175
|
+
const tls = this.options && this.options.tls
|
|
176
|
+
? this.options.tls
|
|
177
|
+
: {};
|
|
178
|
+
// these options are not available in Deno
|
|
179
|
+
(0, internal_mod_js_1.checkUnsupportedOption)("tls.ca", tls.ca);
|
|
180
|
+
(0, internal_mod_js_1.checkUnsupportedOption)("tls.cert", tls.cert);
|
|
181
|
+
(0, internal_mod_js_1.checkUnsupportedOption)("tls.certFile", tls.certFile);
|
|
182
|
+
(0, internal_mod_js_1.checkUnsupportedOption)("tls.key", tls.key);
|
|
183
|
+
(0, internal_mod_js_1.checkUnsupportedOption)("tls.keyFile", tls.keyFile);
|
|
184
|
+
const sto = { hostname };
|
|
185
|
+
if (tls.caFile) {
|
|
186
|
+
const ca = await Deno.readTextFile(tls.caFile);
|
|
187
|
+
sto.caCerts = [ca];
|
|
188
|
+
}
|
|
189
|
+
return sto;
|
|
190
|
+
}
|
|
191
|
+
async startTLS(hostname) {
|
|
192
|
+
const sto = await (this.loadTlsOptions(hostname));
|
|
193
|
+
this.conn = await Deno.startTls(
|
|
194
|
+
//@ts-ignore: just the conn
|
|
195
|
+
this.conn, sto);
|
|
196
|
+
// this is necessary because the startTls process doesn't
|
|
197
|
+
// reject a bad certificate, however the next write will.
|
|
198
|
+
// to identify this as the error, we force it
|
|
199
|
+
await this.conn.write(internal_mod_js_1.Empty);
|
|
200
|
+
this.encrypted = true;
|
|
201
|
+
}
|
|
202
|
+
async *[Symbol.asyncIterator]() {
|
|
203
|
+
let reason;
|
|
204
|
+
// yield what we initially read
|
|
205
|
+
yield this.buf;
|
|
206
|
+
while (!this.done) {
|
|
207
|
+
try {
|
|
208
|
+
this.buf = new Uint8Array(ReadBufferSize);
|
|
209
|
+
const c = await this.conn.read(this.buf);
|
|
210
|
+
if (c === null) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (c) {
|
|
214
|
+
const frame = this.buf.subarray(0, c);
|
|
215
|
+
if (this.options.debug) {
|
|
216
|
+
console.info(`> ${(0, internal_mod_js_1.render)(frame)}`);
|
|
217
|
+
}
|
|
218
|
+
yield frame;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
reason = err;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
this._closed(reason).then().catch();
|
|
227
|
+
}
|
|
228
|
+
maybeWriteFrame() {
|
|
229
|
+
if (this.pendingWrite) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const frame = this.frames.shift();
|
|
233
|
+
if (!frame) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.pendingWrite = (0, mod_js_1.writeAll)(this.conn, frame).then(() => {
|
|
237
|
+
this.pendingWrite = null;
|
|
238
|
+
this.maybeWriteFrame();
|
|
239
|
+
}).then(() => {
|
|
240
|
+
if (this.options.debug) {
|
|
241
|
+
console.info(`< ${(0, internal_mod_js_1.render)(frame)}`);
|
|
242
|
+
}
|
|
243
|
+
}).catch((err) => {
|
|
244
|
+
if (this.options.debug) {
|
|
245
|
+
console.error(`!!! ${(0, internal_mod_js_1.render)(frame)}: ${err}`);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
send(frame) {
|
|
250
|
+
// if we are closed, don't do anything
|
|
251
|
+
if (this.done) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// push the frame
|
|
255
|
+
this.frames.push(frame);
|
|
256
|
+
this.maybeWriteFrame();
|
|
257
|
+
}
|
|
258
|
+
isEncrypted() {
|
|
259
|
+
return this.encrypted;
|
|
260
|
+
}
|
|
261
|
+
close(err) {
|
|
262
|
+
return this._closed(err, false);
|
|
263
|
+
}
|
|
264
|
+
disconnect() {
|
|
265
|
+
this._closed(undefined, true)
|
|
266
|
+
.then().catch();
|
|
267
|
+
}
|
|
268
|
+
async _closed(err, internal = true) {
|
|
269
|
+
if (this.done) {
|
|
270
|
+
// it is possible for close to be called before the connection
|
|
271
|
+
// ever happens or after the protocol requested a close (async connection/upgrade)
|
|
272
|
+
// so even if we already cleaned up, attempt to close the connection
|
|
273
|
+
try {
|
|
274
|
+
this.conn?.close();
|
|
275
|
+
}
|
|
276
|
+
catch (_err) {
|
|
277
|
+
// ignored
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.done = true;
|
|
282
|
+
this.closeError = err;
|
|
283
|
+
if (!err && internal) {
|
|
284
|
+
try {
|
|
285
|
+
// this is a noop but gives us a place to hang
|
|
286
|
+
// a close and ensure that we sent all before closing
|
|
287
|
+
// we wait for the operation to fail or succeed
|
|
288
|
+
this.frames.push(internal_mod_js_1.Empty);
|
|
289
|
+
this.maybeWriteFrame();
|
|
290
|
+
if (this.pendingWrite) {
|
|
291
|
+
await this.pendingWrite;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
if (this.options.debug) {
|
|
296
|
+
console.log("transport close terminated with an error", err);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
this.conn?.close();
|
|
302
|
+
}
|
|
303
|
+
catch (_err) {
|
|
304
|
+
// ignored
|
|
305
|
+
}
|
|
306
|
+
if (internal) {
|
|
307
|
+
this.closedNotification.resolve(err);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
closed() {
|
|
311
|
+
return this.closedNotification;
|
|
312
|
+
}
|
|
313
|
+
discard() {
|
|
314
|
+
// ignored - this is not required, as there's no throttling
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
exports.DenoTransport = DenoTransport;
|
|
318
|
+
async function denoResolveHost(s) {
|
|
319
|
+
const a = Deno.resolveDns(s, "A");
|
|
320
|
+
const aaaa = Deno.resolveDns(s, "AAAA");
|
|
321
|
+
const ips = [];
|
|
322
|
+
const w = await Promise.allSettled([a, aaaa]);
|
|
323
|
+
if (w[0].status === "fulfilled") {
|
|
324
|
+
ips.push(...w[0].value);
|
|
325
|
+
}
|
|
326
|
+
if (w[1].status === "fulfilled") {
|
|
327
|
+
ips.push(...w[1].value);
|
|
328
|
+
}
|
|
329
|
+
if (ips.length === 0) {
|
|
330
|
+
ips.push(s);
|
|
331
|
+
}
|
|
332
|
+
return ips;
|
|
333
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../../src/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,cAAc,qCAAqC,CAAC"}
|