@factorialco/fcode-cli 1.1.0

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 (234) hide show
  1. package/README.md +1021 -0
  2. package/bin/dev +17 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/run +7 -0
  5. package/bin/run.cmd +3 -0
  6. package/dist/commands/add.d.ts +6 -0
  7. package/dist/commands/add.js +22 -0
  8. package/dist/commands/clone.d.ts +26 -0
  9. package/dist/commands/clone.js +177 -0
  10. package/dist/commands/dependencies/add.d.ts +9 -0
  11. package/dist/commands/dependencies/add.js +13 -0
  12. package/dist/commands/dependencies/install.d.ts +14 -0
  13. package/dist/commands/dependencies/install.js +44 -0
  14. package/dist/commands/dependencies/pull.d.ts +12 -0
  15. package/dist/commands/dependencies/pull.js +14 -0
  16. package/dist/commands/dependencies/push.d.ts +12 -0
  17. package/dist/commands/dependencies/push.js +14 -0
  18. package/dist/commands/dependencies/reset.d.ts +9 -0
  19. package/dist/commands/dependencies/reset.js +13 -0
  20. package/dist/commands/dependencies/status.d.ts +9 -0
  21. package/dist/commands/dependencies/status.js +13 -0
  22. package/dist/commands/http.d.ts +22 -0
  23. package/dist/commands/http.js +272 -0
  24. package/dist/commands/login.d.ts +18 -0
  25. package/dist/commands/login.js +62 -0
  26. package/dist/commands/logout.d.ts +10 -0
  27. package/dist/commands/logout.js +34 -0
  28. package/dist/commands/modules/add.d.ts +9 -0
  29. package/dist/commands/modules/add.js +13 -0
  30. package/dist/commands/modules/pull.d.ts +13 -0
  31. package/dist/commands/modules/pull.js +43 -0
  32. package/dist/commands/modules/push.d.ts +13 -0
  33. package/dist/commands/modules/push.js +35 -0
  34. package/dist/commands/modules/remove.d.ts +9 -0
  35. package/dist/commands/modules/remove.js +19 -0
  36. package/dist/commands/modules/reset.d.ts +9 -0
  37. package/dist/commands/modules/reset.js +13 -0
  38. package/dist/commands/modules/status.d.ts +11 -0
  39. package/dist/commands/modules/status.js +40 -0
  40. package/dist/commands/pre-debug.d.ts +20 -0
  41. package/dist/commands/pre-debug.js +120 -0
  42. package/dist/commands/process-metadata.d.ts +18 -0
  43. package/dist/commands/process-metadata.js +63 -0
  44. package/dist/commands/processes/add.d.ts +9 -0
  45. package/dist/commands/processes/add.js +13 -0
  46. package/dist/commands/processes/install-dependencies.d.ts +14 -0
  47. package/dist/commands/processes/install-dependencies.js +30 -0
  48. package/dist/commands/processes/pull.d.ts +13 -0
  49. package/dist/commands/processes/pull.js +47 -0
  50. package/dist/commands/processes/push.d.ts +13 -0
  51. package/dist/commands/processes/push.js +39 -0
  52. package/dist/commands/processes/remove.d.ts +9 -0
  53. package/dist/commands/processes/remove.js +19 -0
  54. package/dist/commands/processes/reset.d.ts +9 -0
  55. package/dist/commands/processes/reset.js +13 -0
  56. package/dist/commands/processes/status.d.ts +11 -0
  57. package/dist/commands/processes/status.js +58 -0
  58. package/dist/commands/pull.d.ts +9 -0
  59. package/dist/commands/pull.js +32 -0
  60. package/dist/commands/push.d.ts +9 -0
  61. package/dist/commands/push.js +29 -0
  62. package/dist/commands/remote/add.d.ts +10 -0
  63. package/dist/commands/remote/add.js +32 -0
  64. package/dist/commands/remote/list.d.ts +7 -0
  65. package/dist/commands/remote/list.js +33 -0
  66. package/dist/commands/remote/set.d.ts +10 -0
  67. package/dist/commands/remote/set.js +28 -0
  68. package/dist/commands/reset.d.ts +6 -0
  69. package/dist/commands/reset.js +19 -0
  70. package/dist/commands/run.d.ts +16 -0
  71. package/dist/commands/run.js +56 -0
  72. package/dist/commands/runtime-env.d.ts +12 -0
  73. package/dist/commands/runtime-env.js +42 -0
  74. package/dist/commands/settings/get.d.ts +12 -0
  75. package/dist/commands/settings/get.js +67 -0
  76. package/dist/commands/settings/remove.d.ts +9 -0
  77. package/dist/commands/settings/remove.js +35 -0
  78. package/dist/commands/settings/set.d.ts +10 -0
  79. package/dist/commands/settings/set.js +39 -0
  80. package/dist/commands/setup-debug.d.ts +12 -0
  81. package/dist/commands/setup-debug.js +118 -0
  82. package/dist/commands/status.d.ts +6 -0
  83. package/dist/commands/status.js +22 -0
  84. package/dist/commands/team/pull.d.ts +8 -0
  85. package/dist/commands/team/pull.js +23 -0
  86. package/dist/commands/team/push.d.ts +11 -0
  87. package/dist/commands/team/push.js +41 -0
  88. package/dist/commands/team/status.d.ts +8 -0
  89. package/dist/commands/team/status.js +40 -0
  90. package/dist/commands/test/scaffold.d.ts +9 -0
  91. package/dist/commands/test/scaffold.js +61 -0
  92. package/dist/commands/test.d.ts +13 -0
  93. package/dist/commands/test.js +72 -0
  94. package/dist/commands/variables/add.d.ts +12 -0
  95. package/dist/commands/variables/add.js +21 -0
  96. package/dist/commands/variables/pull.d.ts +12 -0
  97. package/dist/commands/variables/pull.js +14 -0
  98. package/dist/commands/variables/push.d.ts +12 -0
  99. package/dist/commands/variables/push.js +14 -0
  100. package/dist/commands/variables/remove.d.ts +9 -0
  101. package/dist/commands/variables/remove.js +19 -0
  102. package/dist/commands/variables/reset.d.ts +9 -0
  103. package/dist/commands/variables/reset.js +13 -0
  104. package/dist/commands/variables/status.d.ts +12 -0
  105. package/dist/commands/variables/status.js +58 -0
  106. package/dist/config/global.d.ts +15 -0
  107. package/dist/config/global.js +77 -0
  108. package/dist/config/index.d.ts +14 -0
  109. package/dist/config/index.js +44 -0
  110. package/dist/config/remote.d.ts +15 -0
  111. package/dist/config/remote.js +60 -0
  112. package/dist/config/settings.d.ts +16 -0
  113. package/dist/config/settings.js +54 -0
  114. package/dist/config/workspace.d.ts +28 -0
  115. package/dist/config/workspace.js +158 -0
  116. package/dist/core/commands/api-client-command.d.ts +6 -0
  117. package/dist/core/commands/api-client-command.js +30 -0
  118. package/dist/core/commands/base-command.d.ts +11 -0
  119. package/dist/core/commands/base-command.js +61 -0
  120. package/dist/core/commands/dependency-command.d.ts +5 -0
  121. package/dist/core/commands/dependency-command.js +16 -0
  122. package/dist/core/commands/modules-command.d.ts +7 -0
  123. package/dist/core/commands/modules-command.js +18 -0
  124. package/dist/core/commands/processes-command.d.ts +8 -0
  125. package/dist/core/commands/processes-command.js +27 -0
  126. package/dist/core/commands/resource-command.d.ts +24 -0
  127. package/dist/core/commands/resource-command.js +92 -0
  128. package/dist/core/commands/variables-command.d.ts +5 -0
  129. package/dist/core/commands/variables-command.js +16 -0
  130. package/dist/core/dependencies/env-dependencies-command.d.ts +19 -0
  131. package/dist/core/dependencies/env-dependencies-command.js +70 -0
  132. package/dist/core/dependencies/env-process-dependencies-command.d.ts +15 -0
  133. package/dist/core/dependencies/env-process-dependencies-command.js +78 -0
  134. package/dist/core/dependencies/javascript-env-dependencies.d.ts +8 -0
  135. package/dist/core/dependencies/javascript-env-dependencies.js +77 -0
  136. package/dist/core/dependencies/python-env-dependencies.d.ts +9 -0
  137. package/dist/core/dependencies/python-env-dependencies.js +91 -0
  138. package/dist/core/errors.d.ts +55 -0
  139. package/dist/core/errors.js +144 -0
  140. package/dist/core/executors/execution-task.d.ts +29 -0
  141. package/dist/core/executors/execution-task.js +139 -0
  142. package/dist/core/executors/javascript-execution-task.d.ts +13 -0
  143. package/dist/core/executors/javascript-execution-task.js +618 -0
  144. package/dist/core/executors/python/context.d.ts +2 -0
  145. package/dist/core/executors/python/context.js +3 -0
  146. package/dist/core/executors/python/datastore.d.ts +2 -0
  147. package/dist/core/executors/python/datastore.js +4 -0
  148. package/dist/core/executors/python-execution-task.d.ts +11 -0
  149. package/dist/core/executors/python-execution-task.js +173 -0
  150. package/dist/core/executors/source-code-sanitizer.d.ts +4 -0
  151. package/dist/core/executors/source-code-sanitizer.js +45 -0
  152. package/dist/core/resource-merger.d.ts +14 -0
  153. package/dist/core/resource-merger.js +155 -0
  154. package/dist/core/resource-pusher.d.ts +12 -0
  155. package/dist/core/resource-pusher.js +133 -0
  156. package/dist/core/resource-repository.d.ts +8 -0
  157. package/dist/core/resource-repository.js +2 -0
  158. package/dist/core/types.d.ts +290 -0
  159. package/dist/core/types.js +238 -0
  160. package/dist/core/utils/dependencies.d.ts +5 -0
  161. package/dist/core/utils/dependencies.js +82 -0
  162. package/dist/core/utils/variables.d.ts +4 -0
  163. package/dist/core/utils/variables.js +10 -0
  164. package/dist/hooks/init/auth.d.ts +3 -0
  165. package/dist/hooks/init/auth.js +28 -0
  166. package/dist/hooks/init/update.d.ts +3 -0
  167. package/dist/hooks/init/update.js +42 -0
  168. package/dist/index.d.ts +1 -0
  169. package/dist/index.js +4 -0
  170. package/dist/repositories/process.d.ts +36 -0
  171. package/dist/repositories/process.js +339 -0
  172. package/dist/repositories/programming-language-manifest.d.ts +17 -0
  173. package/dist/repositories/programming-language-manifest.js +95 -0
  174. package/dist/repositories/resource.d.ts +29 -0
  175. package/dist/repositories/resource.js +79 -0
  176. package/dist/repositories/script-library.d.ts +28 -0
  177. package/dist/repositories/script-library.js +164 -0
  178. package/dist/repositories/team.d.ts +23 -0
  179. package/dist/repositories/team.js +74 -0
  180. package/dist/repositories/variable.d.ts +26 -0
  181. package/dist/repositories/variable.js +174 -0
  182. package/dist/runtime/executor.js +87 -0
  183. package/dist/runtime/executor.py +81 -0
  184. package/dist/runtime/libs/node/fcode/index.js +1 -0
  185. package/dist/runtime/libs/python/fcode/__init__.py +75 -0
  186. package/dist/runtime/libs/python/fcode/context.py +98 -0
  187. package/dist/runtime/libs/python/fcode/datastore.py +35 -0
  188. package/dist/runtime/libs/python/fcode/schedule.py +45 -0
  189. package/dist/runtime/libs/python/fcode/storage.py +271 -0
  190. package/dist/runtime/libs/python/fcode/variables.py +102 -0
  191. package/dist/services/auth-service.d.ts +12 -0
  192. package/dist/services/auth-service.js +114 -0
  193. package/dist/services/credential-prompter.d.ts +6 -0
  194. package/dist/services/credential-prompter.js +60 -0
  195. package/dist/services/fcode-graphql-client.d.ts +45 -0
  196. package/dist/services/fcode-graphql-client.js +721 -0
  197. package/dist/services/http-server.d.ts +3 -0
  198. package/dist/services/http-server.js +17 -0
  199. package/dist/services/oauth-browser-service.d.ts +9 -0
  200. package/dist/services/oauth-browser-service.js +164 -0
  201. package/dist/services/process-parameters-sampler.d.ts +2 -0
  202. package/dist/services/process-parameters-sampler.js +41 -0
  203. package/dist/services/process-runner.d.ts +22 -0
  204. package/dist/services/process-runner.js +97 -0
  205. package/dist/services/resource-checker.d.ts +8 -0
  206. package/dist/services/resource-checker.js +82 -0
  207. package/dist/services/test-runner.d.ts +17 -0
  208. package/dist/services/test-runner.js +228 -0
  209. package/dist/utils/canonical-hash.d.ts +9 -0
  210. package/dist/utils/canonical-hash.js +30 -0
  211. package/dist/utils/cli/index.d.ts +14 -0
  212. package/dist/utils/cli/index.js +50 -0
  213. package/dist/utils/cli/screen.d.ts +2 -0
  214. package/dist/utils/cli/screen.js +25 -0
  215. package/dist/utils/cli/styled/table.d.ts +23 -0
  216. package/dist/utils/cli/styled/table.js +272 -0
  217. package/dist/utils/colorize-resource.d.ts +1 -0
  218. package/dist/utils/colorize-resource.js +7 -0
  219. package/dist/utils/env-utils.d.ts +2 -0
  220. package/dist/utils/env-utils.js +16 -0
  221. package/dist/utils/file-utils.d.ts +11 -0
  222. package/dist/utils/file-utils.js +33 -0
  223. package/dist/utils/filenamify.d.ts +4 -0
  224. package/dist/utils/filenamify.js +73 -0
  225. package/dist/utils/gitignore.d.ts +17 -0
  226. package/dist/utils/gitignore.js +60 -0
  227. package/dist/utils/promise.d.ts +4 -0
  228. package/dist/utils/promise.js +38 -0
  229. package/dist/utils/url-utils.d.ts +2 -0
  230. package/dist/utils/url-utils.js +10 -0
  231. package/dist/utils/variable-warnings.d.ts +8 -0
  232. package/dist/utils/variable-warnings.js +38 -0
  233. package/oclif.manifest.json +1783 -0
  234. package/package.json +129 -0
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable camelcase */
4
+ const cli_1 = require("../utils/cli");
5
+ const node_fetch_1 = require("node-fetch");
6
+ const global_1 = require("../config/global");
7
+ const color_1 = require("@oclif/color");
8
+ const AUTH_URL_PATH = '/protocol/openid-connect';
9
+ const AUTH_CLIENT_ID = 'cli';
10
+ const AuthService = {
11
+ clientId: process.env.FCODE_CLIENT_ID || AUTH_CLIENT_ID,
12
+ async getToken({ authUrl, email, password, clientId, clientSecret }) {
13
+ let body;
14
+ let headers;
15
+ if (email && password) {
16
+ body = new URLSearchParams({
17
+ client_id: this.clientId,
18
+ grant_type: 'password',
19
+ password: password || '',
20
+ scope: 'openid',
21
+ username: email || '',
22
+ });
23
+ headers = {
24
+ 'Content-Type': 'application/x-www-form-urlencoded',
25
+ };
26
+ }
27
+ else if (clientId && clientSecret) {
28
+ body = new URLSearchParams({
29
+ grant_type: 'client_credentials',
30
+ scope: 'openid',
31
+ });
32
+ headers = {
33
+ 'Content-Type': 'application/x-www-form-urlencoded',
34
+ Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
35
+ };
36
+ }
37
+ else {
38
+ throw new Error('You must provide email/password or clientId/clientSecret');
39
+ }
40
+ const response = await (0, node_fetch_1.default)(`${authUrl}${AUTH_URL_PATH}/token`, {
41
+ body: body.toString(),
42
+ headers,
43
+ method: 'POST',
44
+ });
45
+ const token = await response.json();
46
+ if (response.ok) {
47
+ return token;
48
+ }
49
+ throw token.error_description;
50
+ },
51
+ async getUserInfo(authUrl, token) {
52
+ const response = await (0, node_fetch_1.default)(`${authUrl}${AUTH_URL_PATH}/userinfo`, {
53
+ headers: {
54
+ Authorization: `Bearer ${token.access_token}`,
55
+ },
56
+ method: 'GET',
57
+ });
58
+ const data = await response.json();
59
+ if (response.ok) {
60
+ return data;
61
+ }
62
+ throw data.error_description;
63
+ },
64
+ globalConfig: new global_1.default(),
65
+ async isAuthenticated(url) {
66
+ try {
67
+ const { authUrl, token } = await this.globalConfig.getAuthInfo(url);
68
+ try {
69
+ await this.getUserInfo(authUrl, token);
70
+ }
71
+ catch (error) {
72
+ await this.globalConfig.clearAuthInfo(url);
73
+ cli_1.default.log(color_1.default.yellow('🚪 Session expired, please login again'));
74
+ throw error;
75
+ }
76
+ return true;
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ },
82
+ async login({ url, authUrl, email, password, clientId, clientSecret, accessToken }) {
83
+ const token = accessToken
84
+ ? { access_token: accessToken, refresh_token: '' }
85
+ : await this.getToken({ url, authUrl, email, password, clientId, clientSecret });
86
+ const userInfo = await this.getUserInfo(authUrl, token);
87
+ const authInfo = {
88
+ authUrl,
89
+ token,
90
+ userInfo,
91
+ };
92
+ await this.globalConfig.setAuthInfo(url, authInfo);
93
+ return authInfo;
94
+ },
95
+ async logout(url) {
96
+ const authInfo = await this.globalConfig.getAuthInfo(url);
97
+ if (authInfo) {
98
+ const body = new URLSearchParams({
99
+ client_id: this.clientId,
100
+ refresh_token: authInfo.token.refresh_token,
101
+ });
102
+ await (0, node_fetch_1.default)(`${url}/logout`, {
103
+ body: body.toString(),
104
+ headers: {
105
+ Authorization: `Bearer ${authInfo.token.access_token}`,
106
+ 'Content-Type': 'application/x-www-form-urlencoded',
107
+ },
108
+ method: 'POST',
109
+ });
110
+ await this.globalConfig.clearAuthInfo(url);
111
+ }
112
+ },
113
+ };
114
+ exports.default = AuthService;
@@ -0,0 +1,6 @@
1
+ import type { Credentials } from '../core/types';
2
+ declare function prompt(credentials?: Credentials): Promise<Credentials>;
3
+ declare const _default: {
4
+ prompt: typeof prompt;
5
+ };
6
+ export default _default;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const auth_service_1 = require("./auth-service");
4
+ const cli_1 = require("../utils/cli");
5
+ const url_utils_1 = require("../utils/url-utils");
6
+ const credentialsQuestions = {
7
+ email: () => cli_1.default.prompt('What is your fcode email?'),
8
+ password: () => cli_1.default.password('What is your fcode password (not stored)?'),
9
+ };
10
+ async function prompt(credentials) {
11
+ const auth = async (credentials) => {
12
+ let { authUrl, url, email, password, clientId, clientSecret } = credentials;
13
+ if (url.endsWith('/')) {
14
+ url = url.slice(0, -1);
15
+ }
16
+ if (authUrl && authUrl.endsWith('/')) {
17
+ authUrl = authUrl.slice(0, -1);
18
+ }
19
+ if (!clientId && !clientSecret) {
20
+ let message = `👤 Logging for Factorial Code account at ${url}`;
21
+ if (!(0, url_utils_1.isDefaultAuthUrl)(authUrl, url)) {
22
+ message += ` (with authUrl ${authUrl})`;
23
+ }
24
+ cli_1.default.log(message);
25
+ email ||= await credentialsQuestions.email();
26
+ password ||= await credentialsQuestions.password();
27
+ }
28
+ try {
29
+ cli_1.default.action.start('🔑 Checking credentials');
30
+ await auth_service_1.default.login({
31
+ authUrl,
32
+ url,
33
+ email,
34
+ password,
35
+ clientId,
36
+ clientSecret,
37
+ });
38
+ cli_1.default.action.stop();
39
+ }
40
+ catch (error) {
41
+ cli_1.default.action.stop();
42
+ cli_1.default.error('Bad credentials. Try again');
43
+ return auth({
44
+ authUrl: credentials.authUrl,
45
+ url: credentials.url,
46
+ email: '',
47
+ password: '',
48
+ });
49
+ }
50
+ };
51
+ return auth(credentials || {
52
+ authUrl: '',
53
+ url: '',
54
+ email: '',
55
+ password: '',
56
+ });
57
+ }
58
+ exports.default = {
59
+ prompt,
60
+ };
@@ -0,0 +1,45 @@
1
+ import { GraphQLClient } from 'graphql-request';
2
+ import { Process, ProgrammingLanguage, ProgrammingLanguageManifest, RawTeamSettings, ScriptLibrary, TeamUpdateInput, Variable, VersionedProcess, VersionedScriptLibrary, ServiceAccount } from '../core/types';
3
+ export type FcodeGraphQLClientOptions = {
4
+ url: string;
5
+ accessToken: string;
6
+ teamSlug: string;
7
+ };
8
+ declare class FcodeGraphQLClient {
9
+ client: GraphQLClient;
10
+ private teamSlug;
11
+ private url;
12
+ constructor(options: FcodeGraphQLClientOptions);
13
+ isDuplicatedError(error: any): boolean;
14
+ isEmptyValueError(error: any): boolean;
15
+ cleanError(error: any): any;
16
+ private cloudUnavailableMessage;
17
+ private isNetworkError;
18
+ allProcesses(): Promise<Array<Process>>;
19
+ allVersionedProcesses(processId: string): Promise<Array<VersionedProcess>>;
20
+ createVersionedProcesses(versionedProcess: VersionedProcess): Promise<void>;
21
+ allScriptLibraries(): Promise<Array<ScriptLibrary>>;
22
+ allVersionedScriptLibraries(scriptLibraryId: string): Promise<Array<VersionedScriptLibrary>>;
23
+ createVersionedScriptLibrary(versionedScriptLibrary: VersionedScriptLibrary): Promise<void>;
24
+ allVariables(): Promise<Array<Variable>>;
25
+ private toProcessInput;
26
+ pushProcess(process: Process): Promise<Process>;
27
+ removeProcess(id: String | undefined): Promise<Process>;
28
+ pushScriptLibrary(scriptLibrary: ScriptLibrary): Promise<ScriptLibrary>;
29
+ removeScriptLibrary(id: String | undefined): Promise<Process>;
30
+ pushVariable(variable: Variable): Promise<Variable>;
31
+ updateVariable(variable: Variable): Promise<Variable>;
32
+ removeVariable(id: String | undefined): Promise<Process>;
33
+ programmingLanguageManifest(programmingLanguage: ProgrammingLanguage): Promise<ProgrammingLanguageManifest>;
34
+ private inheritedTeam;
35
+ private mapWebhook;
36
+ mapProcess({ id, slug, name, description, tags, script, readme, manifest, settings, triggers, resolvingTeamSlug }: any): Process;
37
+ team(): Promise<RawTeamSettings>;
38
+ pushTeam(update: TeamUpdateInput): Promise<RawTeamSettings>;
39
+ mapProgrammingLanguageManifest(programmingLanguageManifest: any): ProgrammingLanguageManifest;
40
+ allProgrammingLanguageManifest(): Promise<Array<ProgrammingLanguageManifest>>;
41
+ pushProgrammingLanguageManifest(programmingLanguageManifest: ProgrammingLanguageManifest): Promise<ProgrammingLanguageManifest>;
42
+ allServiceAccounts(): Promise<Array<ServiceAccount>>;
43
+ createServiceAccount(name: string): Promise<ServiceAccount>;
44
+ }
45
+ export default FcodeGraphQLClient;