@unito/integration-cli 0.55.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 (150) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +32 -0
  3. package/bin/run +11 -0
  4. package/bin/run.cmd +3 -0
  5. package/dist/.eslintrc.d.ts +10 -0
  6. package/dist/.eslintrc.js +20 -0
  7. package/dist/integrationGenerator/errors.d.ts +2 -0
  8. package/dist/integrationGenerator/errors.js +6 -0
  9. package/dist/integrationGenerator/index.d.ts +2 -0
  10. package/dist/integrationGenerator/index.js +5 -0
  11. package/dist/integrationGenerator/integrationBoilerplate/.dockerignore +3 -0
  12. package/dist/integrationGenerator/integrationBoilerplate/.eslintrc.js +74 -0
  13. package/dist/integrationGenerator/integrationBoilerplate/.nvmrc +1 -0
  14. package/dist/integrationGenerator/integrationBoilerplate/.prettierignore +1 -0
  15. package/dist/integrationGenerator/integrationBoilerplate/.prettierrc +7 -0
  16. package/dist/integrationGenerator/integrationBoilerplate/.unito.json +1 -0
  17. package/dist/integrationGenerator/integrationBoilerplate/Dockerfile +38 -0
  18. package/dist/integrationGenerator/integrationBoilerplate/README.md +21 -0
  19. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.dockerignore +3 -0
  20. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.eslintrc.js +74 -0
  21. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +1 -0
  22. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierignore +1 -0
  23. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.prettierrc +7 -0
  24. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.unito.json +1 -0
  25. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +38 -0
  26. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/README.md +21 -0
  27. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/package.json +43 -0
  28. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/index.ts +94 -0
  29. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/logger.ts +55 -0
  30. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +22 -0
  31. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/correlationId.ts +13 -0
  32. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/credentials.ts +38 -0
  33. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/request.ts +59 -0
  34. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/index.ts +11 -0
  35. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/me.ts +15 -0
  36. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/routes/root.ts +12 -0
  37. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/tsconfig.json +37 -0
  38. package/dist/integrationGenerator/integrationBoilerplate/package.json +43 -0
  39. package/dist/integrationGenerator/integrationBoilerplate/src/index.ts +90 -0
  40. package/dist/integrationGenerator/integrationBoilerplate/src/logger.ts +37 -0
  41. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/correlationId.ts +18 -0
  42. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/credentials.ts +38 -0
  43. package/dist/integrationGenerator/integrationBoilerplate/src/request.ts +59 -0
  44. package/dist/integrationGenerator/integrationBoilerplate/src/routes/index.ts +11 -0
  45. package/dist/integrationGenerator/integrationBoilerplate/src/routes/me.ts +15 -0
  46. package/dist/integrationGenerator/integrationBoilerplate/src/routes/root.ts +12 -0
  47. package/dist/integrationGenerator/integrationBoilerplate/tsconfig.json +37 -0
  48. package/dist/integrationGenerator/src/index.d.ts +1 -0
  49. package/dist/integrationGenerator/src/index.js +5 -0
  50. package/dist/integrationGenerator/src/resources/index.d.ts +1 -0
  51. package/dist/integrationGenerator/src/resources/index.js +5 -0
  52. package/dist/integrationGenerator/src/resources/integration.d.ts +9 -0
  53. package/dist/integrationGenerator/src/resources/integration.js +60 -0
  54. package/dist/integrationGenerator/test/resources/integration.test.d.ts +1 -0
  55. package/dist/integrationGenerator/test/resources/integration.test.js +51 -0
  56. package/dist/schemas/authorization.json +204 -0
  57. package/dist/schemas/automation.json +81 -0
  58. package/dist/schemas/configuration.json +89 -0
  59. package/dist/scripts/generateTypes.d.ts +8 -0
  60. package/dist/scripts/generateTypes.js +44 -0
  61. package/dist/src/baseCommand.d.ts +14 -0
  62. package/dist/src/baseCommand.js +39 -0
  63. package/dist/src/commands/activity.d.ts +12 -0
  64. package/dist/src/commands/activity.js +75 -0
  65. package/dist/src/commands/dev.d.ts +15 -0
  66. package/dist/src/commands/dev.js +123 -0
  67. package/dist/src/commands/encrypt.d.ts +11 -0
  68. package/dist/src/commands/encrypt.js +50 -0
  69. package/dist/src/commands/init.d.ts +10 -0
  70. package/dist/src/commands/init.js +51 -0
  71. package/dist/src/commands/invite.d.ts +11 -0
  72. package/dist/src/commands/invite.js +71 -0
  73. package/dist/src/commands/login.d.ts +11 -0
  74. package/dist/src/commands/login.js +76 -0
  75. package/dist/src/commands/oauth2.d.ts +10 -0
  76. package/dist/src/commands/oauth2.js +99 -0
  77. package/dist/src/commands/publish.d.ts +28 -0
  78. package/dist/src/commands/publish.js +302 -0
  79. package/dist/src/commands/test.d.ts +9 -0
  80. package/dist/src/commands/test.js +165 -0
  81. package/dist/src/commands/upgrade.d.ts +7 -0
  82. package/dist/src/commands/upgrade.js +88 -0
  83. package/dist/src/configurationTypes.d.ts +209 -0
  84. package/dist/src/configurationTypes.js +49 -0
  85. package/dist/src/errors.d.ts +38 -0
  86. package/dist/src/errors.js +159 -0
  87. package/dist/src/hooks/init/displayLogo.d.ts +3 -0
  88. package/dist/src/hooks/init/displayLogo.js +37 -0
  89. package/dist/src/index.d.ts +1 -0
  90. package/dist/src/index.js +5 -0
  91. package/dist/src/oauth2Helper/oauth2Helper.d.ts +63 -0
  92. package/dist/src/oauth2Helper/oauth2Helper.js +235 -0
  93. package/dist/src/oauth2Helper/types.d.ts +22 -0
  94. package/dist/src/oauth2Helper/types.js +2 -0
  95. package/dist/src/resources/configuration.d.ts +30 -0
  96. package/dist/src/resources/configuration.js +191 -0
  97. package/dist/src/resources/decryption.d.ts +5 -0
  98. package/dist/src/resources/decryption.js +62 -0
  99. package/dist/src/resources/fileSystem.d.ts +2 -0
  100. package/dist/src/resources/fileSystem.js +22 -0
  101. package/dist/src/resources/globalConfiguration.d.ts +13 -0
  102. package/dist/src/resources/globalConfiguration.js +44 -0
  103. package/dist/src/resources/integrations.d.ts +2 -0
  104. package/dist/src/resources/integrations.js +17 -0
  105. package/dist/src/resources/integrationsPlatform.d.ts +2 -0
  106. package/dist/src/resources/integrationsPlatform.js +33 -0
  107. package/dist/src/services/integrationsPlatform.d.ts +36 -0
  108. package/dist/src/services/integrationsPlatform.js +162 -0
  109. package/dist/src/services/oauth2Helper.d.ts +3 -0
  110. package/dist/src/services/oauth2Helper.js +34 -0
  111. package/dist/test/commands/activity.test.d.ts +1 -0
  112. package/dist/test/commands/activity.test.js +62 -0
  113. package/dist/test/commands/dev.test.d.ts +1 -0
  114. package/dist/test/commands/dev.test.js +139 -0
  115. package/dist/test/commands/encrypt.test.d.ts +1 -0
  116. package/dist/test/commands/encrypt.test.js +73 -0
  117. package/dist/test/commands/init.test.d.ts +1 -0
  118. package/dist/test/commands/init.test.js +45 -0
  119. package/dist/test/commands/invite.test.d.ts +1 -0
  120. package/dist/test/commands/invite.test.js +56 -0
  121. package/dist/test/commands/login.test.d.ts +1 -0
  122. package/dist/test/commands/login.test.js +90 -0
  123. package/dist/test/commands/oauth2.test.d.ts +1 -0
  124. package/dist/test/commands/oauth2.test.js +104 -0
  125. package/dist/test/commands/publish.test.d.ts +1 -0
  126. package/dist/test/commands/publish.test.js +429 -0
  127. package/dist/test/commands/test.test.d.ts +1 -0
  128. package/dist/test/commands/test.test.js +171 -0
  129. package/dist/test/commands/upgrade.test.d.ts +1 -0
  130. package/dist/test/commands/upgrade.test.js +47 -0
  131. package/dist/test/errors.test.d.ts +1 -0
  132. package/dist/test/errors.test.js +96 -0
  133. package/dist/test/helpers/init.d.ts +1 -0
  134. package/dist/test/helpers/init.js +6 -0
  135. package/dist/test/mocha.hooks.d.ts +2 -0
  136. package/dist/test/mocha.hooks.js +37 -0
  137. package/dist/test/oauth2Helper/oauth2Helper.test.d.ts +1 -0
  138. package/dist/test/oauth2Helper/oauth2Helper.test.js +150 -0
  139. package/dist/test/resources/configuration.test.d.ts +1 -0
  140. package/dist/test/resources/configuration.test.js +586 -0
  141. package/dist/test/resources/decryption.test.d.ts +1 -0
  142. package/dist/test/resources/decryption.test.js +68 -0
  143. package/dist/test/resources/globalConfiguration.test.d.ts +1 -0
  144. package/dist/test/resources/globalConfiguration.test.js +32 -0
  145. package/dist/test/services/integrationsPlatform.test.d.ts +1 -0
  146. package/dist/test/services/integrationsPlatform.test.js +168 -0
  147. package/dist/test/services/oauth2Helper.test.d.ts +1 -0
  148. package/dist/test/services/oauth2Helper.test.js +85 -0
  149. package/oclif.manifest.json +423 -0
  150. package/package.json +98 -0
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const child_process_1 = tslib_1.__importDefault(require("child_process"));
6
+ const baseCommand_1 = require("../baseCommand");
7
+ const errors_1 = require("../errors");
8
+ const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
9
+ const integrations_1 = require("../resources/integrations");
10
+ const configuration_1 = require("../resources/configuration");
11
+ const decryption_1 = require("../resources/decryption");
12
+ class Dev extends baseCommand_1.BaseCommand {
13
+ static description = 'Develop your integration';
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ async catch(error) {
16
+ /* istanbul ignore if */
17
+ if ((0, errors_1.handleError)(error)) {
18
+ this.exit(-1);
19
+ }
20
+ throw error;
21
+ }
22
+ static flags = {
23
+ environment: core_1.Flags.custom({
24
+ description: 'the environment of the platform',
25
+ options: Object.values(GlobalConfiguration.Environment),
26
+ default: GlobalConfiguration.Environment.Production,
27
+ })(),
28
+ verbose: core_1.Flags.boolean({
29
+ description: 'output more (debug) information',
30
+ default: false,
31
+ }),
32
+ crawlMode: core_1.Flags.string({
33
+ description: 'mode to use while crawling the integration graph',
34
+ options: Object.values(configuration_1.CrawlMode),
35
+ default: configuration_1.CrawlMode.FULL,
36
+ }),
37
+ checks: core_1.Flags.string({
38
+ description: 'checks to perform while crawling the integration graph',
39
+ multiple: true,
40
+ default: [],
41
+ }),
42
+ 'config-path': core_1.Flags.string({
43
+ summary: 'relative path to a custom ".unito.json" file',
44
+ description: `Use a custom configuration file instead of the default '.unito.json' or other environment specific
45
+ ones.
46
+
47
+ If you want to force the CLI to use a specific configuration file, you can use this flag to specify the relative
48
+ path from your integration's root folder (with a leading '/').
49
+
50
+ Usage: <%= config.bin %> <%= command.id %> --config-path=/myCustomConfig.json`,
51
+ }),
52
+ };
53
+ async run() {
54
+ (0, integrations_1.validateIsIntegrationDirectory)();
55
+ const { flags } = await this.parse(Dev);
56
+ // Install NPM dependencies.
57
+ core_1.ux.action.start('Installing NPM dependencies');
58
+ child_process_1.default.execSync('npm install', {
59
+ env: { ...process.env, NODE_ENV: 'development' },
60
+ stdio: ['ignore', 'ignore', 'inherit'],
61
+ });
62
+ core_1.ux.action.stop();
63
+ // Resolve the configuration.
64
+ const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
65
+ const configuration = await (0, configuration_1.getConfiguration)(environment, flags['config-path']);
66
+ const credentialPayload = await (0, decryption_1.decryptTestAccountCredentials)(configuration, environment, configuration_1.CredentialScope.DEVELOPMENT, this.config.configDir);
67
+ // Decrypt secrets, if necessary.
68
+ const secrets = await (0, decryption_1.decryptSecrets)(configuration, environment, this.config.configDir);
69
+ // Launch the debugger.
70
+ const commandArguments = [
71
+ `${process.env.NODE_MODULES_FOLDER}/@unito/integration-debugger/dist/src/index.js`,
72
+ '--integration-url=http://localhost:9200',
73
+ `--spawn-process=npm run dev`,
74
+ `--credential-payload=${JSON.stringify(credentialPayload)}`,
75
+ `--secrets-payload=${JSON.stringify(secrets)}`,
76
+ ];
77
+ if (configuration.graphRelativeUrl) {
78
+ commandArguments.push(`--graph-relative-url=${configuration.graphRelativeUrl}`);
79
+ }
80
+ if (configuration.credentialAccountRelativeUrl) {
81
+ commandArguments.push(`--credential-account-relative-url=${configuration.credentialAccountRelativeUrl}`);
82
+ }
83
+ if (configuration.webhookParsingRelativeUrl) {
84
+ commandArguments.push(`--webhook-parsing-relative-url=${configuration.webhookParsingRelativeUrl}`);
85
+ }
86
+ if (configuration.webhookSubscriptionsRelativeUrl) {
87
+ commandArguments.push(`--webhook-subscriptions-relative-url=${configuration.webhookSubscriptionsRelativeUrl}`);
88
+ }
89
+ if (configuration.webhookAcknowledgeRelativeUrl) {
90
+ commandArguments.push(`--webhook-acknowledge-relative-url=${configuration.webhookAcknowledgeRelativeUrl}`);
91
+ }
92
+ if (flags.checks?.length) {
93
+ commandArguments.push(`--checks=${flags.checks.join(',')}`);
94
+ }
95
+ if (flags.verbose) {
96
+ commandArguments.push('--verbose');
97
+ }
98
+ if (flags['crawlMode'] === configuration_1.CrawlMode.SAMPLE) {
99
+ commandArguments.push('--operation-collection-items-per-page=10');
100
+ commandArguments.push('--operation-collection-follow-next-pages=false');
101
+ }
102
+ if (flags['crawlMode'] === configuration_1.CrawlMode.SINGLE) {
103
+ commandArguments.push('--operation-collection-items-per-page=1');
104
+ commandArguments.push('--operation-collection-follow-next-pages=false');
105
+ }
106
+ core_1.ux.log(`Launching... node ${commandArguments.join(' ')}`);
107
+ const child = child_process_1.default.spawn('node', commandArguments, {
108
+ detached: true,
109
+ stdio: 'inherit',
110
+ env: { ...process.env, NODE_ENV: 'development', PORT: '9200' },
111
+ });
112
+ // istanbul ignore next
113
+ child.on('exit', (code) => {
114
+ process.exit(code);
115
+ });
116
+ // Window change (ex: resize) signal.
117
+ // istanbul ignore next
118
+ process.on('SIGWINCH', () => {
119
+ child.kill('SIGWINCH');
120
+ });
121
+ }
122
+ }
123
+ exports.default = Dev;
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Encrypt extends BaseCommand<typeof Encrypt> {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ };
9
+ catch(error: Error): Promise<void>;
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
+ const baseCommand_1 = require("../baseCommand");
8
+ const errors_1 = require("../errors");
9
+ const integrations_1 = require("../resources/integrations");
10
+ const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
11
+ const IntegrationsPlatform = tslib_1.__importStar(require("../services/integrationsPlatform"));
12
+ const IntegrationConfiguration = tslib_1.__importStar(require("../resources/configuration"));
13
+ const integrationsPlatform_1 = require("../resources/integrationsPlatform");
14
+ class Encrypt extends baseCommand_1.BaseCommand {
15
+ static description = 'Encrypt data';
16
+ static examples = ['<%= config.bin %> <%= command.id %>'];
17
+ static flags = {
18
+ environment: core_1.Flags.custom({
19
+ description: 'the environment of the platform',
20
+ options: Object.values(GlobalConfiguration.Environment),
21
+ default: GlobalConfiguration.Environment.Production,
22
+ })(),
23
+ };
24
+ async catch(error) {
25
+ /* istanbul ignore if */
26
+ if ((0, errors_1.handleError)(error)) {
27
+ this.exit(-1);
28
+ }
29
+ throw error;
30
+ }
31
+ async run() {
32
+ (0, integrations_1.validateIsIntegrationDirectory)();
33
+ const { flags } = await this.parse(Encrypt);
34
+ // Read the configurations.
35
+ const globalConfiguration = await GlobalConfiguration.read(this.config.configDir);
36
+ const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
37
+ const integrationConfiguration = await IntegrationConfiguration.getConfiguration(environment);
38
+ await (0, integrationsPlatform_1.validateAuthenticated)(globalConfiguration, environment);
39
+ const { data } = await inquirer_1.default.prompt({
40
+ name: 'data',
41
+ message: 'Enter text to encrypt',
42
+ type: 'input',
43
+ });
44
+ core_1.ux.action.start('Encrypting data');
45
+ const { encryptedData } = await IntegrationsPlatform.encryptData(integrationConfiguration.name, data);
46
+ core_1.ux.action.stop();
47
+ core_1.ux.log(`Encrypted Data: ${chalk_1.default.greenBright(encryptedData)}`);
48
+ }
49
+ }
50
+ exports.default = Encrypt;
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ export default class Init extends BaseCommand<typeof Init> {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
8
+ catch(error: Error): Promise<void>;
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
+ const Configuration = tslib_1.__importStar(require("../resources/configuration"));
8
+ const integrationGenerator_1 = require("../../integrationGenerator");
9
+ const baseCommand_1 = require("../baseCommand");
10
+ const errors_1 = require("../errors");
11
+ class Init extends baseCommand_1.BaseCommand {
12
+ static description = 'Initialize a new integration';
13
+ static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name pokemon'];
14
+ static flags = {
15
+ name: core_1.Flags.string({ char: 'n', description: 'Name of the integration' }),
16
+ };
17
+ async catch(error) {
18
+ /* istanbul ignore if */
19
+ if ((0, errors_1.handleError)(error)) {
20
+ this.exit(-1);
21
+ }
22
+ throw error;
23
+ }
24
+ async run() {
25
+ const { flags: { name: nameFromFlag }, } = await this.parse(Init);
26
+ const name = nameFromFlag ??
27
+ (await inquirer_1.default.prompt([
28
+ {
29
+ name: 'name',
30
+ prefix: [
31
+ chalk_1.default.gray('Choose a name for your integration.'),
32
+ chalk_1.default.gray('A folder will be created with the value provided.'),
33
+ chalk_1.default.gray('Note that "My Integration" will become "my_integration".'),
34
+ chalk_1.default.greenBright('?'),
35
+ ].join('\n'),
36
+ message: chalk_1.default.yellowBright('What is the name of your integration?'),
37
+ filter: name => name
38
+ .toLowerCase()
39
+ .replace(/ /g, '_')
40
+ .replace(/[^a-z0-9_-]*/g, ''),
41
+ },
42
+ ])).name;
43
+ core_1.ux.action.start('\nInitializing integration');
44
+ const generatedPath = await integrationGenerator_1.Resources.Integration.generateIntegrationSkeleton(name, process.cwd());
45
+ process.chdir(generatedPath);
46
+ await Configuration.writeConfiguration({ name });
47
+ core_1.ux.action.stop();
48
+ core_1.ux.log(`Your integration is available at: ${chalk_1.default.greenBright(generatedPath)}`);
49
+ }
50
+ }
51
+ exports.default = Init;
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Invite extends BaseCommand<typeof Invite> {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ };
9
+ catch(error: Error): Promise<void>;
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
+ const baseCommand_1 = require("../baseCommand");
8
+ const errors_1 = require("../errors");
9
+ const integrations_1 = require("../resources/integrations");
10
+ const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
11
+ const IntegrationsPlatform = tslib_1.__importStar(require("../services/integrationsPlatform"));
12
+ const IntegrationConfiguration = tslib_1.__importStar(require("../resources/configuration"));
13
+ class Invite extends baseCommand_1.BaseCommand {
14
+ static description = 'Invite a user to become a developer of your integration';
15
+ static examples = ['<%= config.bin %> <%= command.id %>'];
16
+ static flags = {
17
+ environment: core_1.Flags.custom({
18
+ description: 'the environment of the platform',
19
+ options: Object.values(GlobalConfiguration.Environment),
20
+ default: GlobalConfiguration.Environment.Production,
21
+ })(),
22
+ };
23
+ async catch(error) {
24
+ /* istanbul ignore if */
25
+ if ((0, errors_1.handleError)(error)) {
26
+ this.exit(-1);
27
+ }
28
+ throw error;
29
+ }
30
+ async run() {
31
+ (0, integrations_1.validateIsIntegrationDirectory)();
32
+ const { flags } = await this.parse(Invite);
33
+ // Read the configurations.
34
+ const globalConfiguration = await GlobalConfiguration.read(this.config.configDir);
35
+ const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
36
+ const integrationConfiguration = await IntegrationConfiguration.getConfiguration(environment);
37
+ // Choose the right API key for the environment.
38
+ let apiKey = undefined;
39
+ if (environment === GlobalConfiguration.Environment.Local) {
40
+ apiKey = globalConfiguration.apiKeyLocal;
41
+ }
42
+ else if (environment === GlobalConfiguration.Environment.Staging) {
43
+ apiKey = globalConfiguration.apiKeyStaging;
44
+ }
45
+ else {
46
+ apiKey = globalConfiguration.apiKey;
47
+ }
48
+ // Setup the platform client.
49
+ IntegrationsPlatform.setApiKey(apiKey);
50
+ IntegrationsPlatform.setEnvironment(environment);
51
+ const { email } = await inquirer_1.default.prompt([
52
+ {
53
+ name: 'email',
54
+ message: 'Type the email of the user you wish to invite:',
55
+ type: 'input',
56
+ },
57
+ ]);
58
+ core_1.ux.action.start('Finding the integration');
59
+ const integration = await IntegrationsPlatform.getIntegrationByName(integrationConfiguration.name);
60
+ if (!integration) {
61
+ core_1.ux.log(chalk_1.default.redBright(`Integration not found! You can only invite users to a published integration.`));
62
+ this.exit(-1);
63
+ }
64
+ core_1.ux.action.stop();
65
+ core_1.ux.action.start('Inviting user');
66
+ await IntegrationsPlatform.inviteUserToIntegration(integration.id, email);
67
+ core_1.ux.action.stop();
68
+ core_1.ux.log(`User successfully added! They should now be able to update and publish this integration.`);
69
+ }
70
+ }
71
+ exports.default = Invite;
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Login extends BaseCommand<typeof Login> {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ };
9
+ catch(error: Error): Promise<void>;
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const gradient = tslib_1.__importStar(require("gradient-string"));
8
+ const baseCommand_1 = require("../baseCommand");
9
+ const errors_1 = require("../errors");
10
+ const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
11
+ const IntegrationsPlatform = tslib_1.__importStar(require("../services/integrationsPlatform"));
12
+ class Login extends baseCommand_1.BaseCommand {
13
+ static description = 'Login to the Integrations Platform';
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ environment: core_1.Flags.custom({
17
+ description: 'the environment of the platform',
18
+ options: Object.values(GlobalConfiguration.Environment),
19
+ default: GlobalConfiguration.Environment.Production,
20
+ })(),
21
+ };
22
+ async catch(error) {
23
+ /* istanbul ignore if */
24
+ if ((0, errors_1.handleError)(error)) {
25
+ this.exit(-1);
26
+ }
27
+ throw error;
28
+ }
29
+ async run() {
30
+ const { flags } = await this.parse(Login);
31
+ // Read the current global configuration.
32
+ const configuration = await GlobalConfiguration.read(this.config.configDir);
33
+ const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
34
+ // Inquire for the API key.
35
+ let apiKey = undefined;
36
+ try {
37
+ apiKey = (await inquirer_1.default.prompt([
38
+ {
39
+ name: 'apiKey',
40
+ message: 'Enter your API key:',
41
+ },
42
+ ])).apiKey;
43
+ }
44
+ catch (err) {
45
+ core_1.ux.log(chalk_1.default.redBright(`failed because: ${(err ?? {}).message}`));
46
+ this.exit(-1);
47
+ }
48
+ // Retrieve the user's profile.
49
+ core_1.ux.action.start('Log in...');
50
+ let profile = undefined;
51
+ IntegrationsPlatform.setEnvironment(environment);
52
+ IntegrationsPlatform.setApiKey(apiKey);
53
+ try {
54
+ profile = await IntegrationsPlatform.getProfile();
55
+ }
56
+ catch (err) {
57
+ core_1.ux.action.stop(chalk_1.default.redBright(`failed because: ${(err ?? {}).message}`));
58
+ this.exit(-1);
59
+ }
60
+ core_1.ux.action.stop();
61
+ core_1.ux.log([chalk_1.default.greenBright('Hello'), gradient.fruit(profile?.email ?? ''), chalk_1.default.greenBright('!')].join(' '));
62
+ // Set the API key in the global configuration.
63
+ if (environment === GlobalConfiguration.Environment.Local) {
64
+ configuration.apiKeyLocal = apiKey;
65
+ }
66
+ else if (environment === GlobalConfiguration.Environment.Staging) {
67
+ configuration.apiKeyStaging = apiKey;
68
+ }
69
+ else {
70
+ configuration.apiKey = apiKey;
71
+ }
72
+ // Write the new global configuration.
73
+ await GlobalConfiguration.write(this.config.configDir, configuration);
74
+ }
75
+ }
76
+ exports.default = Login;
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Oauth2 extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ accountName: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
8
+ catch(error: Error): Promise<void>;
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const configuration_1 = require("../resources/configuration");
8
+ const Oauth2Helper = tslib_1.__importStar(require("../services/oauth2Helper"));
9
+ const configurationTypes_1 = require("../configurationTypes");
10
+ const errors_1 = require("../errors");
11
+ const globalConfiguration_1 = require("../resources/globalConfiguration");
12
+ class Oauth2 extends core_1.Command {
13
+ static description = 'Perform an OAuth2 workflow locally';
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ accountName: core_1.Flags.string({ description: 'Name of the account used to perfom oauth2 actions' }),
17
+ };
18
+ async catch(error) {
19
+ /* istanbul ignore if */
20
+ if ((0, errors_1.handleError)(error)) {
21
+ this.exit(-1);
22
+ }
23
+ throw error;
24
+ }
25
+ async run() {
26
+ const { flags } = await this.parse(Oauth2);
27
+ const accountName = flags.accountName ?? 'development';
28
+ // Might want to expose Environment flag, but for now we'll default to Production
29
+ const configuration = await (0, configuration_1.getConfiguration)(globalConfiguration_1.Environment.Production);
30
+ let oauth2 = configuration.authorizations?.find(authorization => authorization.method === configurationTypes_1.Method.OAUTH2 && authorization.name === accountName && authorization.development)?.oauth2;
31
+ if (!oauth2) {
32
+ const { oauth2Information } = await inquirer_1.default.prompt([
33
+ {
34
+ name: 'oauth2Information',
35
+ type: 'editor',
36
+ message: `${chalk_1.default.yellowBright('OAuth2 credentials')} that will be used to authenticate to the API`,
37
+ validate: (value) => {
38
+ try {
39
+ JSON.parse(value);
40
+ }
41
+ catch (e) {
42
+ return false;
43
+ }
44
+ return true;
45
+ },
46
+ default: JSON.stringify({
47
+ clientId: '',
48
+ clientSecret: '',
49
+ tokenUrl: '',
50
+ authorizationUrl: '',
51
+ scopes: [{ name: '', help: '' }],
52
+ requestContentType: 'application/x-www-form-urlencoded',
53
+ responseContentType: 'application/json',
54
+ grantType: 'authorization_code',
55
+ }, null, 2),
56
+ },
57
+ ]);
58
+ oauth2 = JSON.parse(oauth2Information);
59
+ if (!configuration.authorizations) {
60
+ configuration.authorizations = [];
61
+ }
62
+ configuration.authorizations.push({
63
+ name: 'development',
64
+ method: configurationTypes_1.Method.OAUTH2,
65
+ development: true,
66
+ oauth2,
67
+ });
68
+ core_1.ux.action.start('Saving configuration');
69
+ await (0, configuration_1.writeConfiguration)(configuration);
70
+ core_1.ux.action.stop();
71
+ }
72
+ if (!oauth2) {
73
+ throw new Error('No oauth2 information found');
74
+ }
75
+ const account = accountName === 'development' ? configuration.testAccounts?.development : configuration.testAccounts?.compliance;
76
+ let credentials;
77
+ if (Object.keys(account || {}).length === 0) {
78
+ core_1.ux.action.start(`Starting Oauth2 flow for account: ${accountName}`);
79
+ credentials = await Oauth2Helper.performOAuth2Flow(oauth2);
80
+ core_1.ux.action.stop();
81
+ }
82
+ else {
83
+ if (!account?.refreshToken) {
84
+ core_1.ux.log('No refresh token found, aborting refresh token flow');
85
+ }
86
+ core_1.ux.action.start(`Refreshing test account ${accountName}`);
87
+ credentials = await Oauth2Helper.updateToken({ ...oauth2, refreshToken: account?.refreshToken });
88
+ if (!credentials.refreshToken) {
89
+ credentials.refreshToken = account?.refreshToken;
90
+ }
91
+ core_1.ux.action.stop();
92
+ }
93
+ core_1.ux.action.start(`Saving credentials for account: ${accountName}`);
94
+ await (0, configuration_1.writeTestAccount)(configuration, credentials, accountName);
95
+ core_1.ux.action.stop();
96
+ return;
97
+ }
98
+ }
99
+ exports.default = Oauth2;
@@ -0,0 +1,28 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Publish extends BaseCommand<typeof Publish> {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ 'registry-only': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ preview: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ 'live-preview': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ 'config-path': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ catch(error: Error): Promise<void>;
15
+ run(): Promise<void>;
16
+ private livePreviewIntegration;
17
+ private updateRegistry;
18
+ private copyAndMoveToTmpDir;
19
+ private previewIntegration;
20
+ private publishIntegration;
21
+ private indent;
22
+ private archiveIntegration;
23
+ private hashEmail;
24
+ private generateNewSecrets;
25
+ private reencryptData;
26
+ private getInstructionsImage;
27
+ private getInstructionsMarkdown;
28
+ }