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