@aloma.io/integration-sdk 3.0.1-5 → 3.0.1-6
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/build/builder/index.d.mts +1 -1
- package/build/builder/index.mjs +15 -11
- package/build/builder/runtime-context.d.mts +1 -1
- package/build/builder/runtime-context.mjs +10 -7
- package/build/builder/transform/index.mjs +18 -18
- package/build/cli.mjs +25 -18
- package/build/controller/index.mjs +5 -5
- package/build/index.d.mts +2 -2
- package/build/index.mjs +2 -2
- package/build/internal/dispatcher/index.cjs +41 -30
- package/build/internal/index.cjs +86 -71
- package/build/internal/util/jwe/cli.cjs +3 -3
- package/build/internal/util/jwe/index.cjs +10 -10
- package/build/internal/websocket/config.cjs +7 -7
- package/build/internal/websocket/connection/constants.cjs +3 -3
- package/build/internal/websocket/connection/index.cjs +9 -9
- package/build/internal/websocket/connection/registration.cjs +7 -7
- package/build/internal/websocket/index.cjs +3 -3
- package/build/internal/websocket/transport/durable.cjs +6 -6
- package/build/internal/websocket/transport/index.cjs +18 -18
- package/build/internal/websocket/transport/packet.cjs +2 -2
- package/build/internal/websocket/transport/processor.cjs +5 -5
- package/package.json +1 -1
- package/src/builder/index.mts +26 -19
- package/src/builder/runtime-context.mts +31 -21
- package/src/builder/transform/index.mts +24 -19
- package/src/cli.mts +44 -42
- package/src/controller/index.mts +13 -7
- package/src/index.mts +2 -2
- package/src/internal/dispatcher/index.cjs +61 -44
- package/src/internal/index.cjs +125 -84
- package/src/internal/util/jwe/cli.cjs +3 -3
- package/src/internal/util/jwe/index.cjs +21 -17
- package/src/internal/websocket/config.cjs +12 -8
- package/src/internal/websocket/connection/constants.cjs +3 -3
- package/src/internal/websocket/connection/index.cjs +11 -11
- package/src/internal/websocket/connection/registration.cjs +9 -9
- package/src/internal/websocket/index.cjs +6 -6
- package/src/internal/websocket/transport/durable.cjs +9 -9
- package/src/internal/websocket/transport/index.cjs +30 -26
- package/src/internal/websocket/transport/packet.cjs +4 -4
- package/src/internal/websocket/transport/processor.cjs +12 -9
- package/template/connector/Containerfile +18 -0
- package/template/connector/entrypoint.sh +5 -0
- package/template/connector/package.json +7 -30
- package/template/connector/src/controller/index.mts +12 -0
- package/template/connector/src/index.mts +6 -0
- package/template/connector/tsconfig.json +27 -0
- package/template/connector/src/index.mjs +0 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
class Dispatcher {
|
2
2
|
constructor() {
|
3
|
-
this._config = {fields: {}};
|
3
|
+
this._config = { fields: {} };
|
4
4
|
}
|
5
5
|
|
6
6
|
main(what) {
|
@@ -15,9 +15,9 @@ class Dispatcher {
|
|
15
15
|
oauth: true,
|
16
16
|
fields: {
|
17
17
|
oauthResult: {
|
18
|
-
name:
|
19
|
-
placeholder:
|
20
|
-
type:
|
18
|
+
name: "OAuth Result",
|
19
|
+
placeholder: "will be set by finishing the oauth flow",
|
20
|
+
type: "managed",
|
21
21
|
},
|
22
22
|
},
|
23
23
|
});
|
@@ -25,18 +25,19 @@ class Dispatcher {
|
|
25
25
|
return this;
|
26
26
|
}
|
27
27
|
|
28
|
-
if (!arg.authorizationURL) throw new Error(
|
29
|
-
if (!arg.tokenURL && !arg.finishOAuth)
|
28
|
+
if (!arg.authorizationURL) throw new Error("need a authorizationURL");
|
29
|
+
if (!arg.tokenURL && !arg.finishOAuth)
|
30
|
+
throw new Error("need a tokenURL or finishOAuth()");
|
30
31
|
|
31
|
-
this._oauth = {...arg};
|
32
|
+
this._oauth = { ...arg };
|
32
33
|
|
33
34
|
this.config({
|
34
35
|
oauth: true,
|
35
36
|
fields: {
|
36
37
|
oauthResult: {
|
37
|
-
name:
|
38
|
-
placeholder:
|
39
|
-
type:
|
38
|
+
name: "OAuth Result",
|
39
|
+
placeholder: "will be set by finishing the oauth flow",
|
40
|
+
type: "managed",
|
40
41
|
},
|
41
42
|
},
|
42
43
|
});
|
@@ -45,14 +46,14 @@ class Dispatcher {
|
|
45
46
|
this.config({
|
46
47
|
fields: {
|
47
48
|
clientId: {
|
48
|
-
name:
|
49
|
-
placeholder:
|
50
|
-
type:
|
49
|
+
name: "OAuth Client ID",
|
50
|
+
placeholder: "e.g. 1234",
|
51
|
+
type: "line",
|
51
52
|
},
|
52
53
|
clientSecret: {
|
53
|
-
name:
|
54
|
-
placeholder:
|
55
|
-
type:
|
54
|
+
name: "OAuth Client Secret",
|
55
|
+
placeholder: "e.g. axd5xde",
|
56
|
+
type: "line",
|
56
57
|
},
|
57
58
|
},
|
58
59
|
});
|
@@ -67,15 +68,15 @@ class Dispatcher {
|
|
67
68
|
return this;
|
68
69
|
}
|
69
70
|
|
70
|
-
config({fields, oauth}) {
|
71
|
+
config({ fields, oauth }) {
|
71
72
|
this._config.oauth = this._config.oauth || oauth;
|
72
|
-
this._config.fields = {...fields, ...this._config.fields};
|
73
|
+
this._config.fields = { ...fields, ...this._config.fields };
|
73
74
|
|
74
75
|
return this;
|
75
76
|
}
|
76
77
|
|
77
78
|
resolvers(what) {
|
78
|
-
this._resolvers = {...this._resolvers, ...what};
|
79
|
+
this._resolvers = { ...this._resolvers, ...what };
|
79
80
|
|
80
81
|
return this;
|
81
82
|
}
|
@@ -84,38 +85,39 @@ class Dispatcher {
|
|
84
85
|
this.config({
|
85
86
|
fields: {
|
86
87
|
_endpointToken: {
|
87
|
-
name:
|
88
|
-
placeholder:
|
89
|
-
type:
|
88
|
+
name: "Endpoint Token (set to enable the endpoint)",
|
89
|
+
placeholder: "e.g. 1234",
|
90
|
+
type: "line",
|
90
91
|
plain: true,
|
91
92
|
optional: true,
|
92
93
|
},
|
93
94
|
},
|
94
95
|
});
|
95
96
|
|
96
|
-
this.resolvers({_endpoint: what});
|
97
|
+
this.resolvers({ _endpoint: what });
|
97
98
|
|
98
99
|
return this;
|
99
100
|
}
|
100
101
|
|
101
102
|
startOAuth() {
|
102
|
-
throw new Error(
|
103
|
+
throw new Error("oauth not configured");
|
103
104
|
}
|
104
105
|
|
105
106
|
finishOAuth() {
|
106
|
-
throw new Error(
|
107
|
+
throw new Error("oauth not configured");
|
107
108
|
}
|
108
109
|
|
109
110
|
build() {
|
110
|
-
if (!this._types || !this._resolvers)
|
111
|
+
if (!this._types || !this._resolvers)
|
112
|
+
throw new Error("missing types or resolvers");
|
111
113
|
var local = this;
|
112
114
|
|
113
|
-
const _resolvers = {...this._resolvers};
|
115
|
+
const _resolvers = { ...this._resolvers };
|
114
116
|
|
115
117
|
const main = this._main || (() => {});
|
116
118
|
|
117
119
|
const start = async (transport) => {
|
118
|
-
console.log(
|
120
|
+
console.log("starting ...");
|
119
121
|
await main(transport);
|
120
122
|
};
|
121
123
|
|
@@ -129,19 +131,32 @@ class Dispatcher {
|
|
129
131
|
return current;
|
130
132
|
};
|
131
133
|
|
132
|
-
const execute = async ({query, variables}) => {
|
134
|
+
const execute = async ({ query, variables }) => {
|
133
135
|
if (!Array.isArray(query)) query = [query];
|
134
136
|
|
135
137
|
query = query
|
136
138
|
.filter(
|
137
|
-
(what) =>
|
139
|
+
(what) =>
|
140
|
+
!!what?.trim() &&
|
141
|
+
![
|
142
|
+
"constructor",
|
143
|
+
"__proto__",
|
144
|
+
"toString",
|
145
|
+
"toSource",
|
146
|
+
"prototype",
|
147
|
+
].includes(what)
|
138
148
|
)
|
139
149
|
.slice(0, 20);
|
140
150
|
|
141
151
|
const method = resolveMethod(query);
|
142
|
-
if (!method && !_resolvers.__default)
|
143
|
-
|
144
|
-
|
152
|
+
if (!method && !_resolvers.__default)
|
153
|
+
throw new Error(`${query} not found`);
|
154
|
+
|
155
|
+
return method
|
156
|
+
? method(variables)
|
157
|
+
: _resolvers.__default(
|
158
|
+
variables ? { ...variables, __method: query } : variables
|
159
|
+
);
|
145
160
|
};
|
146
161
|
|
147
162
|
const introspect = () => local._types;
|
@@ -149,30 +164,32 @@ class Dispatcher {
|
|
149
164
|
|
150
165
|
const processPacket = async (packet) => {
|
151
166
|
switch (packet.method()) {
|
152
|
-
case
|
167
|
+
case "connector.introspect":
|
153
168
|
const intro = await introspect({});
|
154
169
|
|
155
|
-
return {configSchema: local._config, introspect: intro};
|
170
|
+
return { configSchema: local._config, introspect: intro };
|
156
171
|
|
157
|
-
case
|
172
|
+
case "connector.start-oauth":
|
158
173
|
return await local.startOAuth(packet.args());
|
159
174
|
|
160
|
-
case
|
175
|
+
case "connector.finish-oauth":
|
161
176
|
return await local.finishOAuth(packet.args());
|
162
177
|
|
163
|
-
case
|
178
|
+
case "connector.query":
|
164
179
|
const ret = await execute(packet.args());
|
165
180
|
|
166
|
-
return typeof ret ===
|
181
|
+
return typeof ret === "object" && !Array.isArray(ret)
|
182
|
+
? ret
|
183
|
+
: { [packet.args().query]: ret };
|
167
184
|
|
168
|
-
case
|
169
|
-
await local.onConfig({...packet.args().secrets});
|
185
|
+
case "connector.set-config":
|
186
|
+
await local.onConfig({ ...packet.args().secrets });
|
170
187
|
|
171
188
|
return;
|
172
189
|
}
|
173
190
|
|
174
|
-
console.dir(packet, {depth: null});
|
175
|
-
throw new Error(
|
191
|
+
console.dir(packet, { depth: null });
|
192
|
+
throw new Error("cannot handle packet");
|
176
193
|
};
|
177
194
|
|
178
195
|
return {
|
@@ -185,4 +202,4 @@ class Dispatcher {
|
|
185
202
|
}
|
186
203
|
}
|
187
204
|
|
188
|
-
module.exports = {Dispatcher};
|
205
|
+
module.exports = { Dispatcher };
|