@hahnpro/flow-cli 2.17.20 → 2025.10.1
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/main.js +1020 -0
- package/package.json +7 -42
- package/views/index.css +1033 -0
- package/LICENSE +0 -21
- package/README.md +0 -66
- package/lib/auth.mjs +0 -152
- package/lib/cli.mjs +0 -792
- package/lib/utils.mjs +0 -217
- package/lib/views/index.css +0 -1
- /package/{lib/views → views}/index.ejs +0 -0
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Hahn PRO
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# `@hahnpro/flow-cli`
|
|
2
|
-
|
|
3
|
-
https://github.com/hahnprojects/flow
|
|
4
|
-
|
|
5
|
-
```shell
|
|
6
|
-
flow-cli --help
|
|
7
|
-
flow-cli [command] --help
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
# Commands
|
|
11
|
-
|
|
12
|
-
## `build [projectName]`
|
|
13
|
-
|
|
14
|
-
Builds specified Project.
|
|
15
|
-
|
|
16
|
-
## `install [projectName]`
|
|
17
|
-
|
|
18
|
-
Installs the dependencies of the specified Project.
|
|
19
|
-
|
|
20
|
-
## `format`
|
|
21
|
-
|
|
22
|
-
Formats all typescript files according to prettier configuration.
|
|
23
|
-
|
|
24
|
-
## `name [projectName]`
|
|
25
|
-
|
|
26
|
-
Installs Dependencies and Builds the specified Project.
|
|
27
|
-
|
|
28
|
-
## `package [projectName]`
|
|
29
|
-
|
|
30
|
-
Builds specified Module and packages it as .zip File for manual upload to the platform.
|
|
31
|
-
|
|
32
|
-
## `publish-module [projectName]`
|
|
33
|
-
|
|
34
|
-
Publishes specified Module to Cloud Platform.
|
|
35
|
-
|
|
36
|
-
- `-f`, `--functions` Publish flow functions.
|
|
37
|
-
- `-u`, `--update` Update existing flow functions.
|
|
38
|
-
|
|
39
|
-
## `publish-functions [projectName]`
|
|
40
|
-
|
|
41
|
-
Publishes all Flow Functions inside specified Module to Cloud Platform.
|
|
42
|
-
|
|
43
|
-
- `-u`, `--update` Update existing flow functions.
|
|
44
|
-
|
|
45
|
-
## `serve [projectName]`
|
|
46
|
-
|
|
47
|
-
Builds and serves your Project. Rebuilding on file changes.
|
|
48
|
-
|
|
49
|
-
## `start [projectName]`
|
|
50
|
-
|
|
51
|
-
Runs your project.
|
|
52
|
-
|
|
53
|
-
## `test [projectName]`
|
|
54
|
-
|
|
55
|
-
Runs tests for your Project.
|
|
56
|
-
|
|
57
|
-
## `generate-schemas [projectName]`
|
|
58
|
-
|
|
59
|
-
Generates Input, Output and Properties-Schemas for the specified project.
|
|
60
|
-
|
|
61
|
-
- `--verbose` Output more information about what is being done.
|
|
62
|
-
- `-h`, `--hide` Hide warnings if Input/OutputProperties classes can´t be found.
|
|
63
|
-
This command generates the schemas and puts them in the `inputStreams` and `outputStreams`
|
|
64
|
-
fields in the json-files of each Flow-Function. It always assumes the properties defined
|
|
65
|
-
in the `Input/OutPutProperties` classes are meant for the default input/output streams.
|
|
66
|
-
If your Function uses different streams you may have to change stream name manually.
|
package/lib/auth.mjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import getPort from 'get-port';
|
|
4
|
-
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
5
|
-
import nconf from 'nconf';
|
|
6
|
-
import open from 'open';
|
|
7
|
-
import openidClient, { custom } from 'openid-client';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import url from 'node:url';
|
|
10
|
-
|
|
11
|
-
import { logger } from './utils.mjs';
|
|
12
|
-
|
|
13
|
-
const BASE_URL = process.env.BASE_URL || process.env.PLATFORM_URL;
|
|
14
|
-
const CLIENT_ID = process.env.CLIENT_ID || process.env.API_USER || 'flow-cli';
|
|
15
|
-
const CLIENT_SECRET = process.env.CLIENT_SECRET || process.env.API_KEY;
|
|
16
|
-
const REALM = process.env.REALM;
|
|
17
|
-
const BUFFER = 120;
|
|
18
|
-
|
|
19
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
20
|
-
const viewsPath = path.join(__dirname, 'views');
|
|
21
|
-
|
|
22
|
-
let server = null;
|
|
23
|
-
nconf.file({ file: path.join(__dirname, 'config') });
|
|
24
|
-
|
|
25
|
-
if (process.env.https_proxy || process.env.http_proxy) {
|
|
26
|
-
custom.setHttpOptionsDefaults({
|
|
27
|
-
agent: new HttpsProxyAgent(process.env.https_proxy || process.env.http_proxy),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function getAccessToken(baseUrl = BASE_URL, realm = REALM) {
|
|
32
|
-
checkEnvironment([
|
|
33
|
-
['BASE_URL', baseUrl],
|
|
34
|
-
['REALM', realm],
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
nconf.load();
|
|
38
|
-
let tokenSet = nconf.get(baseUrl.replace(/:/g, '')) || {};
|
|
39
|
-
if (tokenSet.access_token && tokenSet.expires_at > Date.now() / 1000 + BUFFER) {
|
|
40
|
-
return tokenSet.access_token;
|
|
41
|
-
} else {
|
|
42
|
-
return CLIENT_ID && CLIENT_SECRET
|
|
43
|
-
? new Promise(async (resolve, reject) => {
|
|
44
|
-
try {
|
|
45
|
-
const kcIssuer = await openidClient.Issuer.discover(`${baseUrl}/auth/realms/${realm}/`);
|
|
46
|
-
const client = new kcIssuer.Client({
|
|
47
|
-
client_id: CLIENT_ID,
|
|
48
|
-
client_secret: CLIENT_SECRET,
|
|
49
|
-
token_endpoint_auth_method: 'client_secret_jwt',
|
|
50
|
-
});
|
|
51
|
-
tokenSet = await client.grant({ grant_type: 'client_credentials' });
|
|
52
|
-
|
|
53
|
-
nconf.set(baseUrl.replace(/:/g, ''), tokenSet);
|
|
54
|
-
nconf.save((error) => {
|
|
55
|
-
if (error) {
|
|
56
|
-
logger.error(error);
|
|
57
|
-
}
|
|
58
|
-
return resolve(tokenSet.access_token);
|
|
59
|
-
});
|
|
60
|
-
} catch (error) {
|
|
61
|
-
return reject(error);
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
: login(baseUrl, realm);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function login(baseUrl = BASE_URL, realm = REALM) {
|
|
69
|
-
return new Promise(async (resolve, reject) => {
|
|
70
|
-
checkEnvironment([
|
|
71
|
-
['BASE_URL', baseUrl],
|
|
72
|
-
['REALM', realm],
|
|
73
|
-
]);
|
|
74
|
-
|
|
75
|
-
server = null;
|
|
76
|
-
const port = process.env.PORT || (await getPort({ port: 3000 }));
|
|
77
|
-
const redirectUri = `http://localhost:${port}/callback`;
|
|
78
|
-
|
|
79
|
-
const kcIssuer = await openidClient.Issuer.discover(`${baseUrl}/auth/realms/${realm}/`);
|
|
80
|
-
const client = new kcIssuer.Client({
|
|
81
|
-
client_id: 'flow-cli',
|
|
82
|
-
redirect_uris: [redirectUri],
|
|
83
|
-
response_types: ['code'],
|
|
84
|
-
token_endpoint_auth_method: 'none',
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const code_verifier = openidClient.generators.codeVerifier();
|
|
88
|
-
const code_challenge = openidClient.generators.codeChallenge(code_verifier);
|
|
89
|
-
const auhtUrl = client.authorizationUrl({ code_challenge, code_challenge_method: 'S256' });
|
|
90
|
-
|
|
91
|
-
const app = express();
|
|
92
|
-
app.disable('x-powered-by');
|
|
93
|
-
app.use(express.static(viewsPath));
|
|
94
|
-
app.set('views', viewsPath);
|
|
95
|
-
|
|
96
|
-
app.get('/callback', async (request, response) => {
|
|
97
|
-
const parameters = client.callbackParams(request.url);
|
|
98
|
-
if (parameters.code) {
|
|
99
|
-
response.render('index.ejs', { message: 'Authentication successful', hint: 'You can close this window' });
|
|
100
|
-
} else {
|
|
101
|
-
response.render('index.ejs', { message: 'Authentication failed', hint: 'Please try again' });
|
|
102
|
-
}
|
|
103
|
-
response.end();
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const tokenSet = await client.callback(redirectUri, parameters, { code_verifier });
|
|
107
|
-
nconf.set(baseUrl.replace(/:/g, ''), tokenSet);
|
|
108
|
-
server.close();
|
|
109
|
-
nconf.save((error) => {
|
|
110
|
-
if (error) {
|
|
111
|
-
logger.error(error);
|
|
112
|
-
}
|
|
113
|
-
return resolve(tokenSet.access_token);
|
|
114
|
-
});
|
|
115
|
-
} catch (error) {
|
|
116
|
-
return reject(error);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
server = await app.listen(port);
|
|
121
|
-
await open(auhtUrl);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function logout(baseUrl = BASE_URL) {
|
|
126
|
-
return new Promise((resolve, reject) => {
|
|
127
|
-
if (baseUrl) {
|
|
128
|
-
// clears specified key
|
|
129
|
-
nconf.clear(baseUrl.replace(/:/g, ''));
|
|
130
|
-
} else {
|
|
131
|
-
// clears all keys
|
|
132
|
-
nconf.reset();
|
|
133
|
-
}
|
|
134
|
-
server = null;
|
|
135
|
-
nconf.save((error) => {
|
|
136
|
-
return error ? reject(error) : resolve();
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function checkEnvironment(values) {
|
|
142
|
-
let missing = false;
|
|
143
|
-
for (const [name, value] of values) {
|
|
144
|
-
if (!value && !process.env[name]) {
|
|
145
|
-
logger.error(`"${name}" env var is required`);
|
|
146
|
-
missing = true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (missing) {
|
|
150
|
-
throw new Error('Missing environment variables');
|
|
151
|
-
}
|
|
152
|
-
}
|