@useparagon/cli 0.0.1-canary.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.
Files changed (207) hide show
  1. package/dist/codegen/codegen.types.d.ts +9 -0
  2. package/dist/codegen/codegen.types.js +3 -0
  3. package/dist/codegen/codegen.types.js.map +1 -0
  4. package/dist/codegen/codegen.utils.d.ts +4 -0
  5. package/dist/codegen/codegen.utils.js +70 -0
  6. package/dist/codegen/codegen.utils.js.map +1 -0
  7. package/dist/codegen/codegens/condition.codegen.d.ts +2 -0
  8. package/dist/codegen/codegens/condition.codegen.js +28 -0
  9. package/dist/codegen/codegens/condition.codegen.js.map +1 -0
  10. package/dist/codegen/codegens/event.codegen.d.ts +2 -0
  11. package/dist/codegen/codegens/event.codegen.js +35 -0
  12. package/dist/codegen/codegens/event.codegen.js.map +1 -0
  13. package/dist/codegen/codegens/integration.codegen.d.ts +2 -0
  14. package/dist/codegen/codegens/integration.codegen.js +18 -0
  15. package/dist/codegen/codegens/integration.codegen.js.map +1 -0
  16. package/dist/codegen/codegens/source.codegen.d.ts +5 -0
  17. package/dist/codegen/codegens/source.codegen.js +104 -0
  18. package/dist/codegen/codegens/source.codegen.js.map +1 -0
  19. package/dist/codegen/codegens/workflow.codegen.d.ts +3 -0
  20. package/dist/codegen/codegens/workflow.codegen.js +278 -0
  21. package/dist/codegen/codegens/workflow.codegen.js.map +1 -0
  22. package/dist/commands/build/build.action.d.ts +8 -0
  23. package/dist/commands/build/build.action.js +49 -0
  24. package/dist/commands/build/build.action.js.map +1 -0
  25. package/dist/commands/build/build.command.d.ts +8 -0
  26. package/dist/commands/build/build.command.js +27 -0
  27. package/dist/commands/build/build.command.js.map +1 -0
  28. package/dist/commands/build/build.types.d.ts +6 -0
  29. package/dist/commands/build/build.types.js +3 -0
  30. package/dist/commands/build/build.types.js.map +1 -0
  31. package/dist/commands/build/build.utils.d.ts +1 -0
  32. package/dist/commands/build/build.utils.js +17 -0
  33. package/dist/commands/build/build.utils.js.map +1 -0
  34. package/dist/commands/build/index.d.ts +1 -0
  35. package/dist/commands/build/index.js +5 -0
  36. package/dist/commands/build/index.js.map +1 -0
  37. package/dist/commands/command.interface.d.ts +7 -0
  38. package/dist/commands/command.interface.js +3 -0
  39. package/dist/commands/command.interface.js.map +1 -0
  40. package/dist/commands/command.loader.d.ts +5 -0
  41. package/dist/commands/command.loader.js +27 -0
  42. package/dist/commands/command.loader.js.map +1 -0
  43. package/dist/commands/index.d.ts +2 -0
  44. package/dist/commands/index.js +6 -0
  45. package/dist/commands/index.js.map +1 -0
  46. package/dist/commands/init/index.d.ts +1 -0
  47. package/dist/commands/init/index.js +5 -0
  48. package/dist/commands/init/index.js.map +1 -0
  49. package/dist/commands/init/init.action.d.ts +11 -0
  50. package/dist/commands/init/init.action.js +92 -0
  51. package/dist/commands/init/init.action.js.map +1 -0
  52. package/dist/commands/init/init.command.d.ts +8 -0
  53. package/dist/commands/init/init.command.js +27 -0
  54. package/dist/commands/init/init.command.js.map +1 -0
  55. package/dist/commands/init/init.constants.d.ts +1 -0
  56. package/dist/commands/init/init.constants.js +21 -0
  57. package/dist/commands/init/init.constants.js.map +1 -0
  58. package/dist/commands/init/init.types.d.ts +7 -0
  59. package/dist/commands/init/init.types.js +3 -0
  60. package/dist/commands/init/init.types.js.map +1 -0
  61. package/dist/commands/init/init.utils.d.ts +11 -0
  62. package/dist/commands/init/init.utils.js +50 -0
  63. package/dist/commands/init/init.utils.js.map +1 -0
  64. package/dist/commands/login/index.d.ts +1 -0
  65. package/dist/commands/login/index.js +5 -0
  66. package/dist/commands/login/index.js.map +1 -0
  67. package/dist/commands/login/login.command.d.ts +5 -0
  68. package/dist/commands/login/login.command.js +26 -0
  69. package/dist/commands/login/login.command.js.map +1 -0
  70. package/dist/commands/login/login.types.d.ts +3 -0
  71. package/dist/commands/login/login.types.js +3 -0
  72. package/dist/commands/login/login.types.js.map +1 -0
  73. package/dist/commands/login/login.utils.d.ts +2 -0
  74. package/dist/commands/login/login.utils.js +47 -0
  75. package/dist/commands/login/login.utils.js.map +1 -0
  76. package/dist/compilers/compiler.interface.d.ts +3 -0
  77. package/dist/compilers/compiler.interface.js +3 -0
  78. package/dist/compilers/compiler.interface.js.map +1 -0
  79. package/dist/compilers/compiler.types.d.ts +23 -0
  80. package/dist/compilers/compiler.types.js +3 -0
  81. package/dist/compilers/compiler.types.js.map +1 -0
  82. package/dist/compilers/compiler.utils.d.ts +2 -0
  83. package/dist/compilers/compiler.utils.js +25 -0
  84. package/dist/compilers/compiler.utils.js.map +1 -0
  85. package/dist/compilers/event.compiler.d.ts +7 -0
  86. package/dist/compilers/event.compiler.js +25 -0
  87. package/dist/compilers/event.compiler.js.map +1 -0
  88. package/dist/compilers/integration.compiler.d.ts +9 -0
  89. package/dist/compilers/integration.compiler.js +55 -0
  90. package/dist/compilers/integration.compiler.js.map +1 -0
  91. package/dist/compilers/project.compiler.d.ts +10 -0
  92. package/dist/compilers/project.compiler.js +50 -0
  93. package/dist/compilers/project.compiler.js.map +1 -0
  94. package/dist/compilers/ts.compiler.d.ts +11 -0
  95. package/dist/compilers/ts.compiler.js +70 -0
  96. package/dist/compilers/ts.compiler.js.map +1 -0
  97. package/dist/compilers/workflow.compiler.d.ts +10 -0
  98. package/dist/compilers/workflow.compiler.js +36 -0
  99. package/dist/compilers/workflow.compiler.js.map +1 -0
  100. package/dist/config/config.constants.d.ts +4 -0
  101. package/dist/config/config.constants.js +12 -0
  102. package/dist/config/config.constants.js.map +1 -0
  103. package/dist/config/config.types.d.ts +31 -0
  104. package/dist/config/config.types.js +18 -0
  105. package/dist/config/config.types.js.map +1 -0
  106. package/dist/config/config.utils.d.ts +9 -0
  107. package/dist/config/config.utils.js +136 -0
  108. package/dist/config/config.utils.js.map +1 -0
  109. package/dist/config/index.d.ts +2 -0
  110. package/dist/config/index.js +6 -0
  111. package/dist/config/index.js.map +1 -0
  112. package/dist/helpers/constants.d.ts +2 -0
  113. package/dist/helpers/constants.js +6 -0
  114. package/dist/helpers/constants.js.map +1 -0
  115. package/dist/helpers/json.d.ts +1 -0
  116. package/dist/helpers/json.js +8 -0
  117. package/dist/helpers/json.js.map +1 -0
  118. package/dist/helpers/spinners.d.ts +3 -0
  119. package/dist/helpers/spinners.js +6 -0
  120. package/dist/helpers/spinners.js.map +1 -0
  121. package/dist/helpers/strings.d.ts +1 -0
  122. package/dist/helpers/strings.js +8 -0
  123. package/dist/helpers/strings.js.map +1 -0
  124. package/dist/index.d.ts +4 -0
  125. package/dist/index.js +16 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/logger/index.d.ts +1 -0
  128. package/dist/logger/index.js +9 -0
  129. package/dist/logger/index.js.map +1 -0
  130. package/dist/logger/logger.d.ts +3 -0
  131. package/dist/logger/logger.js +50 -0
  132. package/dist/logger/logger.js.map +1 -0
  133. package/dist/logger/logger.type.d.ts +8 -0
  134. package/dist/logger/logger.type.js +3 -0
  135. package/dist/logger/logger.type.js.map +1 -0
  136. package/dist/templates/configurations/javascript/.prettierignore +2 -0
  137. package/dist/templates/configurations/javascript/.prettierrc +11 -0
  138. package/dist/templates/configurations/typescript/.prettierignore +2 -0
  139. package/dist/templates/configurations/typescript/.prettierrc +19 -0
  140. package/dist/templates/javascript/src/events/hello-world.js +13 -0
  141. package/dist/templates/javascript/src/integrations/slack/config.js +11 -0
  142. package/dist/templates/javascript/src/integrations/slack/workflows/example-workflow.js +30 -0
  143. package/dist/templates/typescript/src/events/hello-world.ts +21 -0
  144. package/dist/templates/typescript/src/integrations/slack/config.ts +18 -0
  145. package/dist/templates/typescript/src/integrations/slack/workflows/example-workflow.ts +30 -0
  146. package/dist/templates/typescript/tsconfig.json +31 -0
  147. package/package.json +56 -0
  148. package/paragon.json +3 -0
  149. package/sample/sample.js +404 -0
  150. package/src/codegen/codegen.types.ts +14 -0
  151. package/src/codegen/codegen.utils.ts +145 -0
  152. package/src/codegen/codegens/condition.codegen.ts +49 -0
  153. package/src/codegen/codegens/event.codegen.ts +39 -0
  154. package/src/codegen/codegens/integration.codegen.ts +23 -0
  155. package/src/codegen/codegens/source.codegen.ts +193 -0
  156. package/src/codegen/codegens/workflow.codegen.ts +495 -0
  157. package/src/commands/build/build.action.ts +73 -0
  158. package/src/commands/build/build.command.ts +61 -0
  159. package/src/commands/build/build.types.ts +7 -0
  160. package/src/commands/build/build.utils.ts +21 -0
  161. package/src/commands/build/index.ts +1 -0
  162. package/src/commands/command.interface.ts +22 -0
  163. package/src/commands/command.loader.ts +33 -0
  164. package/src/commands/index.ts +2 -0
  165. package/src/commands/init/index.ts +1 -0
  166. package/src/commands/init/init.action.ts +166 -0
  167. package/src/commands/init/init.command.ts +71 -0
  168. package/src/commands/init/init.constants.ts +29 -0
  169. package/src/commands/init/init.types.ts +8 -0
  170. package/src/commands/init/init.utils.ts +91 -0
  171. package/src/commands/login/index.ts +1 -0
  172. package/src/commands/login/login.command.ts +48 -0
  173. package/src/commands/login/login.types.ts +9 -0
  174. package/src/commands/login/login.utils.ts +68 -0
  175. package/src/compilers/compiler.interface.ts +9 -0
  176. package/src/compilers/compiler.types.ts +52 -0
  177. package/src/compilers/compiler.utils.ts +32 -0
  178. package/src/compilers/event.compiler.ts +33 -0
  179. package/src/compilers/integration.compiler.ts +84 -0
  180. package/src/compilers/project.compiler.ts +86 -0
  181. package/src/compilers/ts.compiler.ts +116 -0
  182. package/src/compilers/workflow.compiler.ts +69 -0
  183. package/src/config/config.constants.ts +27 -0
  184. package/src/config/config.types.ts +112 -0
  185. package/src/config/config.utils.ts +251 -0
  186. package/src/config/index.ts +2 -0
  187. package/src/helpers/constants.ts +9 -0
  188. package/src/helpers/json.ts +8 -0
  189. package/src/helpers/spinners.ts +3 -0
  190. package/src/helpers/strings.ts +9 -0
  191. package/src/index.ts +26 -0
  192. package/src/logger/index.ts +1 -0
  193. package/src/logger/logger.ts +97 -0
  194. package/src/logger/logger.type.ts +8 -0
  195. package/templates/configurations/javascript/.prettierignore +2 -0
  196. package/templates/configurations/javascript/.prettierrc +11 -0
  197. package/templates/configurations/typescript/.prettierignore +2 -0
  198. package/templates/configurations/typescript/.prettierrc +19 -0
  199. package/templates/javascript/src/events/hello-world.js +13 -0
  200. package/templates/javascript/src/integrations/slack/config.js +11 -0
  201. package/templates/javascript/src/integrations/slack/workflows/example-workflow.js +30 -0
  202. package/templates/typescript/src/events/hello-world.ts +21 -0
  203. package/templates/typescript/src/integrations/slack/config.ts +18 -0
  204. package/templates/typescript/src/integrations/slack/workflows/example-workflow.ts +30 -0
  205. package/templates/typescript/tsconfig.json +31 -0
  206. package/tsconfig.json +13 -0
  207. package/tsconfig.release.json +13 -0
@@ -0,0 +1,251 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'fs-extra';
3
+
4
+ import logger from '../logger';
5
+
6
+ import {
7
+ DEFAULT_PROFILE,
8
+ DEFAULT_PROJECT_CONFIG,
9
+ SYSTEM_CONFIG_DIR_PATH,
10
+ } from './config.constants';
11
+ import {
12
+ IAuth,
13
+ IAuthConfig,
14
+ IProfile,
15
+ IProfileAuth,
16
+ IProfileConfig,
17
+ IProjectConfig,
18
+ SystemFile,
19
+ SystemFileToPathMap,
20
+ } from './config.types';
21
+
22
+ /**
23
+ * ensures the system directory and files exist
24
+ */
25
+ export async function initializeSystemFiles(
26
+ systemDirectoryPath: string = SYSTEM_CONFIG_DIR_PATH,
27
+ ): Promise<void> {
28
+ logger.info('Initializing system files...');
29
+ await initializeSystemDirectory(systemDirectoryPath);
30
+ const systemFiles: SystemFile[] = Object.values(SystemFile);
31
+ await Promise.all(
32
+ systemFiles.map((file: SystemFile) =>
33
+ initializeOrUpdateFile(file, systemDirectoryPath),
34
+ ),
35
+ );
36
+ }
37
+
38
+ /**
39
+ * ensures the system directory exists
40
+ */
41
+ export async function initializeSystemDirectory(
42
+ systemDirectoryPath: string,
43
+ ): Promise<void> {
44
+ logger.info('Initializing system directory...', { systemDirectoryPath });
45
+ const isDir: boolean = await fs.exists(systemDirectoryPath);
46
+ if (!isDir) {
47
+ logger.info('Initialized system directory.');
48
+ await fs.mkdir(systemDirectoryPath);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * ensures a system file exists
54
+ *
55
+ * @param file
56
+ */
57
+ export async function initializeOrUpdateFile(
58
+ file: SystemFile,
59
+ systemDirectoryPath: string,
60
+ fileContents?: string,
61
+ ): Promise<void> {
62
+ logger.info('Initializing or updating file...', {
63
+ file,
64
+ systemDirectoryPath,
65
+ });
66
+ const filePath: string = path.resolve(
67
+ systemDirectoryPath,
68
+ SystemFileToPathMap[file],
69
+ );
70
+ const doesExist: boolean = await fs.exists(filePath);
71
+ if (!doesExist || fileContents) {
72
+ logger.info('Initialized or updated file.');
73
+ await fs.writeFile(filePath, fileContents || '{}', { encoding: 'utf-8' });
74
+ }
75
+ }
76
+
77
+ /**
78
+ * reads a system file
79
+ *
80
+ * @param file
81
+ * @param systemDirectoryPath
82
+ */
83
+ async function readFile(
84
+ file: SystemFile.CREDENTIALS,
85
+ systemDirectoryPath: string,
86
+ ): Promise<IAuthConfig>;
87
+ async function readFile(
88
+ file: SystemFile.PROFILES,
89
+ systemDirectoryPath: string,
90
+ ): Promise<IProfileConfig>;
91
+ async function readFile(
92
+ file: SystemFile,
93
+ systemDirectoryPath: string,
94
+ ): Promise<IAuthConfig | IProfileConfig> {
95
+ logger.info('Reading file...', { file, systemDirectoryPath });
96
+ const filePath: string = path.resolve(
97
+ systemDirectoryPath,
98
+ SystemFileToPathMap[file],
99
+ );
100
+ const fileContents: string = await fs.readFile(filePath, 'utf-8');
101
+ return JSON.parse(fileContents);
102
+ }
103
+
104
+ /**
105
+ * creates a default profile
106
+ *
107
+ * @param projectConfig
108
+ */
109
+ async function createDefaultProfile(
110
+ projectConfig: IProjectConfig,
111
+ ): Promise<IProfile> {
112
+ const profile: IProfile = {
113
+ name: DEFAULT_PROFILE,
114
+ default: true,
115
+ };
116
+ const configPath: string =
117
+ projectConfig.config_path ?? SYSTEM_CONFIG_DIR_PATH;
118
+ const currentProfileConfig: IProfileConfig = await readFile(
119
+ SystemFile.PROFILES,
120
+ configPath,
121
+ );
122
+ const updatedProfileConfig: IProfileConfig = {
123
+ ...currentProfileConfig,
124
+ [profile.name]: profile,
125
+ };
126
+ const stringifiedUpdatedProfileConfig: string = JSON.stringify(
127
+ updatedProfileConfig,
128
+ null,
129
+ 2,
130
+ );
131
+ await initializeOrUpdateFile(
132
+ SystemFile.PROFILES,
133
+ configPath,
134
+ stringifiedUpdatedProfileConfig,
135
+ );
136
+ return profile;
137
+ }
138
+
139
+ /**
140
+ * loads the profiles from the file system
141
+ *
142
+ * @todo validate config
143
+ */
144
+ export async function loadProfileConfig(
145
+ projectConfig: IProjectConfig,
146
+ ): Promise<IProfileConfig> {
147
+ const configPath: string =
148
+ projectConfig.config_path ?? SYSTEM_CONFIG_DIR_PATH;
149
+ return readFile(SystemFile.PROFILES, configPath);
150
+ }
151
+
152
+ /**
153
+ * loads the profile used in the project
154
+ *
155
+ * @param projectConfig
156
+ */
157
+ export async function loadProfile(
158
+ projectConfig: IProjectConfig,
159
+ ): Promise<IProfile> {
160
+ const profileConfig: IProfileConfig = await loadProfileConfig(projectConfig);
161
+ const profileName: string = projectConfig.profile ?? DEFAULT_PROFILE;
162
+ let profile: IProfile | undefined =
163
+ profileConfig[profileName] ??
164
+ Object.values(profileConfig).find((profile: IProfile) => profile.default);
165
+ if (!profile) {
166
+ profile = await createDefaultProfile(projectConfig);
167
+ }
168
+ return profile;
169
+ }
170
+
171
+ /**
172
+ * loads the configuration for the project
173
+ *
174
+ * @todo validate config loaded from file system
175
+ */
176
+ export async function loadProjectConfig(): Promise<IProjectConfig> {
177
+ const cwd: string = process.cwd();
178
+ const projectConfigFilePath: string = path.resolve(cwd, 'paragon.json');
179
+ const doesProjectConfigFileExist: boolean = await fs.exists(
180
+ projectConfigFilePath,
181
+ );
182
+ let projectConfig: IProjectConfig;
183
+ if (doesProjectConfigFileExist) {
184
+ const projectConfigString: string = await fs.readFile(
185
+ projectConfigFilePath,
186
+ 'utf-8',
187
+ );
188
+ projectConfig = JSON.parse(projectConfigString);
189
+ if (projectConfig.config_path) {
190
+ projectConfig.config_path = path.resolve(
191
+ process.cwd(),
192
+ projectConfig.config_path,
193
+ );
194
+ }
195
+ } else {
196
+ projectConfig = DEFAULT_PROJECT_CONFIG;
197
+ }
198
+
199
+ await initializeSystemFiles(projectConfig.config_path);
200
+ return projectConfig;
201
+ }
202
+
203
+ /**
204
+ * loads the auth params for a project's specified profile
205
+ *
206
+ * @param projectConfig
207
+ * @todo validate auth before returning
208
+ */
209
+ export async function loadAuthForProfile(
210
+ projectConfig: IProjectConfig,
211
+ ): Promise<IAuth> {
212
+ const configPath: string =
213
+ projectConfig.config_path ?? SYSTEM_CONFIG_DIR_PATH;
214
+ const authConfig: IAuthConfig = await readFile(
215
+ SystemFile.CREDENTIALS,
216
+ configPath,
217
+ );
218
+ const profileName: string = projectConfig.profile ?? DEFAULT_PROFILE;
219
+ const auth: IAuth | undefined = authConfig[profileName];
220
+ if (!auth) {
221
+ throw new Error('No authentication configured for profile');
222
+ }
223
+ // TODO: validate auth
224
+ return auth;
225
+ }
226
+
227
+ /**
228
+ * saving login token to profile
229
+ *
230
+ * @param auth
231
+ * @param projectConfig
232
+ */
233
+ export async function updateAuthForProfile(
234
+ auth: IProfileAuth,
235
+ projectConfig: IProjectConfig,
236
+ ): Promise<void> {
237
+ const configPath: string =
238
+ projectConfig.config_path ?? SYSTEM_CONFIG_DIR_PATH;
239
+ const authConfig: IAuthConfig = await readFile(
240
+ SystemFile.CREDENTIALS,
241
+ configPath,
242
+ );
243
+ const profileName: string = projectConfig.profile ?? DEFAULT_PROFILE;
244
+ authConfig[profileName] = auth;
245
+ const serializedAuthConfig: string = JSON.stringify(authConfig, null, 2);
246
+ await initializeOrUpdateFile(
247
+ SystemFile.CREDENTIALS,
248
+ configPath,
249
+ serializedAuthConfig,
250
+ );
251
+ }
@@ -0,0 +1,2 @@
1
+ export * from './config.types';
2
+ export * from './config.utils';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * language supported by cli
3
+ */
4
+ export const LANGUAGES_SUPPORTED = <const>['typescript', 'javascript'];
5
+
6
+ /**
7
+ * known package managers for node
8
+ */
9
+ export const KNOWN_PACKAGE_MANAGERS = <const>['npm', 'pnpm', 'yarn', 'bun'];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * strigify object with prettier
3
+ * @param value
4
+ * @returns
5
+ */
6
+ export const stringifyObject = (value: object): string => {
7
+ return JSON.stringify(value, null, 2);
8
+ };
@@ -0,0 +1,3 @@
1
+ import spinnnies from 'spinnies';
2
+
3
+ export default new spinnnies();
@@ -0,0 +1,9 @@
1
+ /**
2
+ * capitalize first letter of string
3
+ * example -> "abcd" => "Abcd"
4
+ * @param value
5
+ * @returns
6
+ */
7
+ export const capitalizeFirstLetter = (value: string) => {
8
+ return value.charAt(0).toUpperCase() + value.slice(1);
9
+ };
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env node
2
+
3
+ import * as commander from 'commander';
4
+
5
+ import { CommandLoader } from './commands/command.loader';
6
+
7
+ const program: commander.Command = commander.program
8
+ .version(
9
+ require('../package.json').version,
10
+ '-v, --version',
11
+ 'Output the current version.',
12
+ )
13
+ .usage('<command> [options]')
14
+ .helpOption('-h, --help', 'Output usage information.');
15
+
16
+ //load all commands
17
+ CommandLoader.load(program);
18
+
19
+ // Only run this file if called directly so functions can be exported + used in other files.
20
+ // If it's being called directly, it's being called from from a github action or yarn script
21
+ // In that case, we have to log the result to the console so it can parse it.
22
+ if (require.main === module) {
23
+ program.parse(process.argv);
24
+ }
25
+
26
+ export default program;
@@ -0,0 +1 @@
1
+ export { default } from './logger';
@@ -0,0 +1,97 @@
1
+ import chalk from 'chalk';
2
+
3
+ import { Logger } from './logger.type';
4
+
5
+ // import pino, { DestinationStream, Level, Logger, LoggerOptions } from 'pino';
6
+ // /**
7
+ // * creates a logger
8
+ // *
9
+ // * @todo fix logic for log level when not testing
10
+ // * @todo disable pretty printing in production environment
11
+ // */
12
+ // function configureLogger(): Logger<LoggerOptions | DestinationStream> {
13
+ // const level: Level = process.env.NODE_ENV === 'production' ? 'warn' : 'trace';
14
+ // const options: LoggerOptions = {
15
+ // timestamp: false,
16
+ // level,
17
+ // transport: {
18
+ // target: 'pino-pretty',
19
+ // options: {
20
+ // colorize: true,
21
+ // },
22
+ // },
23
+
24
+ // hooks: {
25
+ // logMethod(args, method) {
26
+ // // console.log(args);
27
+ // const newArgs: typeof args =
28
+ // args.length > 1 &&
29
+ // typeof args[0] === 'string' &&
30
+ // typeof args[1] !== 'string'
31
+ // ? [args[1], args[0], ...args.slice(2)]
32
+ // : args;
33
+ // method.apply(this, newArgs);
34
+ // },
35
+ // },
36
+ // };
37
+ // return pino(options);
38
+ // }
39
+
40
+ enum LOG_LEVEL {
41
+ ERROR,
42
+ // exit process on
43
+ FATAL,
44
+ INFO,
45
+ LOG,
46
+ SUCCESS,
47
+ WARNING,
48
+ }
49
+
50
+ /**
51
+ * log message with color
52
+ * @param logLevel
53
+ * @param args
54
+ */
55
+ const logWithColor = (logLevel: LOG_LEVEL, ...messages: any[]): void => {
56
+ let completeMessage: string = '';
57
+
58
+ for (const message of messages) {
59
+ if (typeof message === 'object') {
60
+ completeMessage += ` ${JSON.stringify(message, null, 2)}`;
61
+ continue;
62
+ }
63
+ completeMessage += ` ${message}`;
64
+ }
65
+
66
+ switch (logLevel) {
67
+ case LOG_LEVEL.INFO:
68
+ console.log(chalk.blueBright(completeMessage));
69
+ break;
70
+ case LOG_LEVEL.WARNING:
71
+ console.log('⚠️ ', chalk.yellow(completeMessage));
72
+ break;
73
+ case LOG_LEVEL.ERROR:
74
+ console.log('❌ ', chalk.red(completeMessage));
75
+ break;
76
+ case LOG_LEVEL.FATAL:
77
+ console.log('❌ ', chalk.red(completeMessage));
78
+ process.exit(1);
79
+ case LOG_LEVEL.SUCCESS:
80
+ console.log('✅ ', chalk.green(completeMessage));
81
+ break;
82
+ }
83
+ };
84
+
85
+ /**
86
+ * pino-prettier not writing synchrounously to terminal so for now using simple console
87
+ */
88
+ const logger: Logger = {
89
+ error: (...messages: any[]) => logWithColor(LOG_LEVEL.ERROR, ...messages),
90
+ fatal: (...messages: any[]) => logWithColor(LOG_LEVEL.FATAL, ...messages),
91
+ info: (...messages: any[]) => logWithColor(LOG_LEVEL.INFO, ...messages),
92
+ log: console.log,
93
+ success: (...messages: any[]) => logWithColor(LOG_LEVEL.SUCCESS, ...messages),
94
+ warn: (...messages: any[]) => logWithColor(LOG_LEVEL.WARNING, ...messages),
95
+ };
96
+
97
+ export default logger;
@@ -0,0 +1,8 @@
1
+ export type Logger = {
2
+ error: (...messages: any[]) => void;
3
+ fatal: (...messages: any[]) => void;
4
+ info: (...messages: any[]) => void;
5
+ log: (...messages: any[]) => void;
6
+ success: (...messages: any[]) => void;
7
+ warn: (...messages: any[]) => void;
8
+ };
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
@@ -0,0 +1,11 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "organizeImportsSkipDestructiveCodeActions": true,
5
+ "importOrder": [
6
+ "^@useparagon/(.*)$",
7
+ "^[./]"
8
+ ],
9
+ "importOrderSeparation": true,
10
+ "importOrderCaseInsensitive": true
11
+ }
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
@@ -0,0 +1,19 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "overrides": [
5
+ {
6
+ "files": "*.ts",
7
+ "options": {
8
+ "parser": "typescript"
9
+ }
10
+ }
11
+ ],
12
+ "organizeImportsSkipDestructiveCodeActions": true,
13
+ "importOrder": [
14
+ "^@useparagon/(.*)$",
15
+ "^[./]"
16
+ ],
17
+ "importOrderSeparation": true,
18
+ "importOrderCaseInsensitive": true
19
+ }
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ /**
3
+ * name of event
4
+ */
5
+ name: 'hello-world',
6
+
7
+ /**
8
+ * schema of event payload
9
+ */
10
+ schema: {
11
+ message: 'Hello,world',
12
+ },
13
+ };
@@ -0,0 +1,11 @@
1
+ export default {
2
+ description: 'Slack Integration',
3
+ overviewText: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
4
+
5
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
6
+
7
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
8
+
9
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
10
+ scopes: 'channel:read',
11
+ };
@@ -0,0 +1,30 @@
1
+ import { EventStep, FunctionStep, Workflow } from '@useparagon/core';
2
+ import { IContext } from '@useparagon/core/execution';
3
+
4
+ import event from '../../../events/hello';
5
+
6
+ /**
7
+ * example workflow triggered by an app event
8
+ */
9
+ export default class ExampleWorkflow extends Workflow {
10
+ /**
11
+ * defines the workflow
12
+ * @param integration
13
+ * @param context
14
+ * @param user
15
+ */
16
+ define(integration, context) {
17
+ const trigger = new EventStep(event);
18
+ const fn = new FunctionStep({
19
+ code: (parameters) => {
20
+ return parameters.message;
21
+ },
22
+ parameters: {
23
+ message: context.getOutput(trigger)?.message,
24
+ },
25
+ });
26
+
27
+ trigger.nextStep(fn);
28
+ return this.register({ trigger, fn });
29
+ }
30
+ }
@@ -0,0 +1,21 @@
1
+ import { IEvent } from '@useparagon/core/event';
2
+
3
+ type EventSchema = {
4
+ message: string;
5
+ };
6
+
7
+ const event: IEvent<EventSchema> = {
8
+ /**
9
+ * name of event
10
+ */
11
+ name: 'hello-world',
12
+
13
+ /**
14
+ * schema of event payload
15
+ */
16
+ schema: {
17
+ message: 'Hello,world',
18
+ },
19
+ };
20
+
21
+ export default event;
@@ -0,0 +1,18 @@
1
+ import { IIntegrationConfig } from '@useparagon/core';
2
+
3
+ /**
4
+ * configuration for a dummy integration
5
+ */
6
+ const config: IIntegrationConfig = {
7
+ description: 'A dummy BYO integration.',
8
+ overviewText: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
9
+
10
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
11
+
12
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
13
+
14
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
15
+ scopes: 'user:read',
16
+ };
17
+
18
+ export default config;
@@ -0,0 +1,30 @@
1
+ import { EventStep, FunctionStep, Workflow } from '@useparagon/core';
2
+ import { IContext } from '@useparagon/core/execution';
3
+
4
+ import event from '../../../events/hello-world';
5
+
6
+ /**
7
+ * example workflow triggered by an app event
8
+ */
9
+ export default class MyWorkflow extends Workflow<any> {
10
+ /**
11
+ * defines the workflow
12
+ * @param integration
13
+ * @param context
14
+ * @param user
15
+ */
16
+ define(_integration: any, context: IContext) {
17
+ const trigger = new EventStep(event);
18
+ const fn = new FunctionStep({
19
+ code: (parameters: Record<string, unknown>) => {
20
+ return parameters.message;
21
+ },
22
+ parameters: {
23
+ message: context.getOutput(trigger)?.message,
24
+ },
25
+ });
26
+
27
+ trigger.nextStep(fn);
28
+ return this.register({ trigger, fn });
29
+ }
30
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "allowUnreachableCode": false,
6
+ "alwaysStrict": true,
7
+ "declaration": true,
8
+ "emitDecoratorMetadata": true,
9
+ "esModuleInterop": true,
10
+ "experimentalDecorators": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "importHelpers": true,
13
+ "isolatedModules": false,
14
+ "jsx": "react",
15
+ "module": "commonjs",
16
+ "moduleResolution": "node",
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitAny": false,
19
+ "noImplicitReturns": true,
20
+ "noImplicitThis": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "removeComments": true,
24
+ "resolveJsonModule": true,
25
+ "sourceMap": true,
26
+ "strict": true,
27
+ "strictNullChecks": true,
28
+ "target": "es6",
29
+ }
30
+ }
31
+
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["./src", "./templates"],
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ "baseUrl": "./"
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../core"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.release.json",
3
+ "include": ["./src/"],
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ "baseUrl": "./"
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../core"
11
+ }
12
+ ]
13
+ }