@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,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const chai_1 = require("chai");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const sinon = tslib_1.__importStar(require("sinon"));
7
+ const tmp_1 = tslib_1.__importDefault(require("tmp"));
8
+ const fs_1 = tslib_1.__importDefault(require("fs"));
9
+ const Integration = tslib_1.__importStar(require("../../src/resources/integration"));
10
+ describe('Integration Resource Generation', () => {
11
+ let tempDir;
12
+ const boilerplatePath = path.join(__dirname, '../../integrationBoilerplate');
13
+ afterEach(() => {
14
+ sinon.restore();
15
+ });
16
+ describe('generateIntegrationSkeleton', () => {
17
+ beforeEach(() => {
18
+ tempDir = tmp_1.default.dirSync({ prefix: 'outputIntegrations-' }).name;
19
+ });
20
+ afterEach(async () => {
21
+ await fs_1.default.promises.rm(tempDir, { recursive: true });
22
+ sinon.restore();
23
+ });
24
+ it('should not create a new integration directory if it already exists', async () => {
25
+ const existingIntegrationName = 'existingIntegration';
26
+ await Integration.generateIntegrationSkeleton(existingIntegrationName, tempDir);
27
+ try {
28
+ await Integration.generateIntegrationSkeleton(existingIntegrationName, tempDir);
29
+ }
30
+ catch (e) {
31
+ (0, chai_1.expect)(e).to.eql(new Error(`Integration already exists with this name: ${existingIntegrationName}`));
32
+ }
33
+ });
34
+ it('should create a new integration directory if it does not exist', async () => {
35
+ const integrationName = 'NewIntegration';
36
+ const result = await Integration.generateIntegrationSkeleton(integrationName, tempDir);
37
+ (0, chai_1.expect)(result).equal(path.join(tempDir, integrationName.toLowerCase()));
38
+ (0, chai_1.expect)(fs_1.default.existsSync(result)).to.be.true;
39
+ const expectedFiles = await fs_1.default.promises.readdir(boilerplatePath);
40
+ expectedFiles.push('.npmrc');
41
+ const createdFiles = await fs_1.default.promises.readdir(result);
42
+ (0, chai_1.expect)(createdFiles).to.deep.eq(expectedFiles.sort());
43
+ createdFiles.forEach(createdField => (0, chai_1.expect)(expectedFiles.includes(createdField)));
44
+ });
45
+ it('generates an .npmrc file', async () => {
46
+ const result = await Integration.generateIntegrationSkeleton('foo', tempDir);
47
+ const npmrc = await fs_1.default.promises.readFile(`${result}/.npmrc`, 'utf-8');
48
+ (0, chai_1.expect)(npmrc).to.include('//npm.pkg.github.com/:_authToken=${UNITO_GITHUB_PKG_TOKEN}');
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,204 @@
1
+ {
2
+ "$id": "https://unito.io/integration_cli/authorization.schema.json",
3
+ "title": "Authorization",
4
+ "type": "object",
5
+ "description": "An authorization is a way to obtain and generate credentials for an integration",
6
+ "additionalProperties": false,
7
+ "required": ["name", "method"],
8
+ "properties": {
9
+ "name": {
10
+ "type": "string"
11
+ },
12
+ "development": {
13
+ "type": "boolean",
14
+ "description": "Whether the authorization is used locally for development purposes only"
15
+ },
16
+ "instructionsImage": {
17
+ "description": "The Base64-encoded data URL of an <img> src content or null. For example: 'data:image/png;base64,<base64>'",
18
+ "anyOf": [{ "type": "null" }, { "type": "string" }]
19
+ },
20
+ "instructionsMarkdown": {
21
+ "description": "A string representing a markdown document or null",
22
+ "anyOf": [{ "type": "null" }, { "type": "string" }]
23
+ },
24
+ "method": {
25
+ "type": "string",
26
+ "description": "The method of authorization",
27
+ "enum": ["custom", "oauth2"],
28
+ "tsEnumNames": ["CUSTOM", "OAUTH2"]
29
+ },
30
+ "oauth2": {
31
+ "$ref": "#/$defs/oauth2"
32
+ },
33
+ "variables": {
34
+ "type": "object",
35
+ "description": "Variables to obtain credentials from an end-user",
36
+ "additionalProperties": false,
37
+ "patternProperties": {
38
+ "^(?!refreshToken$)(?!accessToken$)(?!scope$)(?!expiresIn$)(?!tokenType$)(?!oauth2ExtraParameters$).*$": {
39
+ "type": "object",
40
+ "additionalProperties": false,
41
+ "required": ["type"],
42
+ "properties": {
43
+ "type": {
44
+ "type": "string",
45
+ "enum": ["boolean", "number", "password", "string", "text"],
46
+ "tsEnumNames": ["BOOLEAN", "NUMBER", "PASSWORD", "STRING", "TEXT"]
47
+ },
48
+ "format": {
49
+ "type": "string",
50
+ "description": "The JSON Schema format that the value of the variable must comply to",
51
+ "enum": ["email", "uri"],
52
+ "tsEnumNames": ["EMAIL", "URI"]
53
+ },
54
+ "pattern": {
55
+ "description": "The JSON Schema regular expression template for the string value. Only the values that match this template will be accepted. The regular expression syntax used is from JavaScript (more specifically, ECMA 262)",
56
+ "type": "string"
57
+ },
58
+ "label": {
59
+ "type": "string"
60
+ },
61
+ "required": {
62
+ "type": "boolean"
63
+ },
64
+ "defaultValue": {
65
+ "oneOf": [
66
+ { "type": "string" },
67
+ { "type": "number" },
68
+ { "type": "boolean" }
69
+ ]
70
+ },
71
+ "placeholder": {
72
+ "type": "string"
73
+ },
74
+ "help": {
75
+ "type": "string"
76
+ },
77
+ "documentationUrl": {
78
+ "type": "string",
79
+ "format": "uri"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "$defs": {
87
+ "authorizationResponseContentType": {
88
+ "type": "string",
89
+ "description": "The content type of exchanged information with the provider",
90
+ "enum": ["application/x-www-form-urlencoded", "application/json"],
91
+ "tsEnumNames": ["URL_ENCODED", "JSON"]
92
+ },
93
+ "authorizationRequestParameters": {
94
+ "type": "object",
95
+ "description": "The extra information used to communicate with the provider",
96
+ "additionalProperties": false,
97
+ "properties": {
98
+ "header": {
99
+ "type": "object",
100
+ "description": "Extra information to include in the HTTP request headers",
101
+ "additionalProperties": {
102
+ "oneOf": [
103
+ {
104
+ "description": "A string",
105
+ "type": "string"
106
+ },
107
+ {
108
+ "description": "A number",
109
+ "type": "number"
110
+ },
111
+ {
112
+ "description": "A boolean",
113
+ "type": "boolean"
114
+ }
115
+ ]
116
+ }
117
+ },
118
+ "body": {
119
+ "type": "object",
120
+ "description": "Extra information to include in the HTTP request body",
121
+ "additionalProperties": {
122
+ "oneOf": [
123
+ {
124
+ "description": "A string",
125
+ "type": "string"
126
+ },
127
+ {
128
+ "description": "A number",
129
+ "type": "number"
130
+ },
131
+ {
132
+ "description": "A boolean",
133
+ "type": "boolean"
134
+ }
135
+ ]
136
+ }
137
+ }
138
+ }
139
+ },
140
+ "oauth2": {
141
+ "type": "object",
142
+ "description": "Parameters to obtain OAuth 2 credentials from an end-user",
143
+ "additionalProperties": false,
144
+ "required": ["tokenUrl", "scopes"],
145
+ "properties": {
146
+ "clientSecret": {
147
+ "type": "string",
148
+ "description": "The Client Secret obtained from the provider."
149
+ },
150
+ "clientId": {
151
+ "type": "string",
152
+ "description": "The Client Id obtained from the provider."
153
+ },
154
+ "authorizationUrl": {
155
+ "type": "string",
156
+ "description": "The URL to grant or deny access to the user account.",
157
+ "format": "uri-template"
158
+ },
159
+ "tokenUrl": {
160
+ "type": "string",
161
+ "description": "The URL to obtain or refresh an access token.",
162
+ "format": "uri-template"
163
+ },
164
+ "grantType": {
165
+ "type": "string",
166
+ "description": "The type of grant of the OAuth 2 authorization",
167
+ "enum": ["authorization_code", "password"],
168
+ "tsEnumNames": ["AUTHORIZATION_CODE", "PASSWORD"]
169
+ },
170
+ "scopes": {
171
+ "type": "array",
172
+ "items": {
173
+ "type": "object",
174
+ "description": "The requested scope of access to the user account",
175
+ "additionalProperties": false,
176
+ "required": ["name"],
177
+ "properties": {
178
+ "name": {
179
+ "type": "string",
180
+ "description": "The name of the scope"
181
+ },
182
+ "help": {
183
+ "type": "string",
184
+ "description": "Message to the end-user to explain the usage of the scope by Unito"
185
+ }
186
+ }
187
+ }
188
+ },
189
+ "tokenRequestParameters": {
190
+ "$ref": "#/$defs/authorizationRequestParameters"
191
+ },
192
+ "refreshRequestParameters": {
193
+ "$ref": "#/$defs/authorizationRequestParameters"
194
+ },
195
+ "requestContentType": {
196
+ "$ref": "#/$defs/authorizationResponseContentType"
197
+ },
198
+ "responseContentType": {
199
+ "$ref": "#/$defs/authorizationResponseContentType"
200
+ }
201
+ }
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,81 @@
1
+ {
2
+ "$id": "https://unito.io/integration_cli/automation.schema.json",
3
+ "title": "Automation",
4
+ "type": "object",
5
+ "description": "The configuration of the automation of an integration",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "headers": {
9
+ "type": "object",
10
+ "description": "The headers to add to the request",
11
+ "required": ["authorizationHeaderPrefix"],
12
+ "properties": {
13
+ "authorizationHeaderPrefix": {
14
+ "type": "string",
15
+ "description": "The value of the Authorization header. e.g \"Bearer\""
16
+ }
17
+ },
18
+ "additionalProperties": {
19
+ "type": "string",
20
+ "description": "Custom headers values"
21
+ }
22
+ },
23
+ "items": {
24
+ "type": "object",
25
+ "description": "The items to generate",
26
+ "additionalProperties": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "properties": {
30
+ "collection": {
31
+ "$ref": "#/$defs/endpoint"
32
+ },
33
+ "item": {
34
+ "$ref": "#/$defs/endpoint"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ },
40
+ "$defs": {
41
+ "endpoint": {
42
+ "type": "object",
43
+ "description": "The endpoint to generate",
44
+ "additionalProperties": false,
45
+ "required": ["endpointURI", "idKey"],
46
+ "properties": {
47
+ "endpointURI": {
48
+ "type": "string",
49
+ "description": "Endpoint of the resource e.g /foo/bar/resource"
50
+ },
51
+ "idKey": {
52
+ "type": "string",
53
+ "description": "Which field is the unique identifier (id) of your item"
54
+ },
55
+ "keyToResponse": {
56
+ "type": "string",
57
+ "description": "Key to Access Nested Item (if applicable) like \"data\" that will lead to the item"
58
+ },
59
+ "usedId": {
60
+ "type": "string",
61
+ "default": ""
62
+ },
63
+ "directParent": {
64
+ "type": "string",
65
+ "default": ""
66
+ },
67
+ "httpMethod": {
68
+ "type": "string",
69
+ "description": "The verb of the HTTP request",
70
+ "default": "GET",
71
+ "enum": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
72
+ "tsEnumNames": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]
73
+ },
74
+ "body": {
75
+ "type": "string",
76
+ "default": ""
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,89 @@
1
+ {
2
+ "$id": "https://unito.io/integration_cli/configuration.schema.json",
3
+ "title": "Configuration",
4
+ "type": "object",
5
+ "description": "The configuration of an integration",
6
+ "additionalProperties": false,
7
+ "required": ["name"],
8
+ "properties": {
9
+ "name": {
10
+ "type": "string",
11
+ "pattern": "^[a-z0-9_-]+$",
12
+ "description": "The name of the integration"
13
+ },
14
+ "baseUrl": {
15
+ "type": "string",
16
+ "description": "The base URL where the integration is located",
17
+ "default": ""
18
+ },
19
+ "graphRelativeUrl": {
20
+ "type": "string",
21
+ "description": "The relative URL (to the baseUrl) where the graph of items of the integration is located",
22
+ "default": "/"
23
+ },
24
+ "credentialAccountRelativeUrl": {
25
+ "type": "string",
26
+ "description": "The relative URL (to the baseUrl) to fetch the current integration's authenticated user",
27
+ "default": "/me"
28
+ },
29
+ "webhookParsingRelativeUrl": {
30
+ "type": ["string", "null"],
31
+ "description": "The relative URL (to the baseUrl) to parse a webhook payload"
32
+ },
33
+ "webhookSubscriptionsRelativeUrl": {
34
+ "type": ["string", "null"],
35
+ "description": "The relative URL (to the baseUrl) to operate on webhook subscriptions"
36
+ },
37
+ "webhookAcknowledgeRelativeUrl": {
38
+ "type": ["string", "null"],
39
+ "description": "The relative URL (to the baseUrl) to acknowledge webhook sender"
40
+ },
41
+ "ui": {
42
+ "type": "object",
43
+ "description": "The UI-related information of the integration",
44
+ "additionalProperties": false,
45
+ "properties": {
46
+ "displayName": {
47
+ "type": "string",
48
+ "description": "The name of the integration, as it should be displayed in a UI"
49
+ },
50
+ "logo": {
51
+ "type": "string",
52
+ "description": "Base64-encoded SVG of the logo of the integration"
53
+ }
54
+ }
55
+ },
56
+ "authorizations": {
57
+ "type": "array",
58
+ "description": "The authorizations of the integration",
59
+ "items": {
60
+ "$ref": "https://unito.io/integration_cli/authorization.schema.json"
61
+ }
62
+ },
63
+ "testAccounts": {
64
+ "type": "object",
65
+ "description": "The test accounts of the integration",
66
+ "additionalProperties": false,
67
+ "properties": {
68
+ "development": {
69
+ "type": "object",
70
+ "description": "Test account for local development",
71
+ "additionalProperties": true
72
+ },
73
+ "compliance": {
74
+ "type": "object",
75
+ "description": "Test account for compliance tests",
76
+ "additionalProperties": true
77
+ }
78
+ }
79
+ },
80
+ "secrets": {
81
+ "type": "object",
82
+ "description": "The secrets of the integration",
83
+ "additionalProperties": {
84
+ "type": "string",
85
+ "pattern": "^unito-secret-v[0-9]+:\/\/.*$"
86
+ }
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generate the Integration CLI types
3
+ *
4
+ * Execute with:
5
+ *
6
+ * npx ts-node scripts/generateTypes.ts
7
+ */
8
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Generate the Integration CLI types
4
+ *
5
+ * Execute with:
6
+ *
7
+ * npx ts-node scripts/generateTypes.ts
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const tslib_1 = require("tslib");
11
+ const json_schema_to_typescript_1 = require("json-schema-to-typescript");
12
+ const fs = tslib_1.__importStar(require("fs"));
13
+ async function execute() {
14
+ const directory = `${__dirname}/../schemas`;
15
+ const compiled = await (0, json_schema_to_typescript_1.compileFromFile)(`${directory}/configuration.json`, {
16
+ declareExternallyReferenced: true,
17
+ enableConstEnums: false,
18
+ style: {
19
+ bracketSpacing: true,
20
+ printWidth: 120,
21
+ semi: true,
22
+ singleQuote: true,
23
+ useTabs: false,
24
+ tabWidth: 2,
25
+ trailingComma: 'all',
26
+ },
27
+ unknownAny: true,
28
+ $refOptions: {
29
+ resolve: {
30
+ local: {
31
+ order: 1,
32
+ canRead: true,
33
+ read: async function (file, _callback) {
34
+ const filename = file.url.split('https://unito.io/integration_cli/').at(1)?.split('.schema.json')?.at(0);
35
+ return fs.readFileSync(`${directory}/${filename}.json`, 'utf8');
36
+ },
37
+ },
38
+ },
39
+ },
40
+ });
41
+ console.log(compiled);
42
+ }
43
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
44
+ execute();
@@ -0,0 +1,14 @@
1
+ import { Command, Interfaces } from '@oclif/core';
2
+ export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)['baseFlags'] & T['flags']>;
3
+ export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
4
+ export declare abstract class BaseCommand<T extends typeof Command> extends Command {
5
+ static enableJsonFlag: boolean;
6
+ protected flags: Flags<T>;
7
+ protected args: Args<T>;
8
+ init(): Promise<void>;
9
+ run(): Promise<void>;
10
+ protected catch(err: Error & {
11
+ exitCode?: number;
12
+ }): Promise<any>;
13
+ protected finally(_: Error | undefined): Promise<any>;
14
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseCommand = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ class BaseCommand extends core_1.Command {
6
+ // add the --json flag
7
+ static enableJsonFlag = true;
8
+ flags;
9
+ args;
10
+ async init() {
11
+ await super.init();
12
+ const { args, flags } = await this.parse({
13
+ flags: this.ctor.flags,
14
+ args: this.ctor.args,
15
+ strict: this.ctor.strict,
16
+ });
17
+ this.flags = flags;
18
+ this.args = args;
19
+ }
20
+ // istanbul ignore next
21
+ async run() {
22
+ // emit analytics
23
+ await this.config.runHook('checkConfig', { id: 'my_command' });
24
+ }
25
+ // istanbul ignore next
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ async catch(err) {
28
+ // add any custom logic to handle errors from the command
29
+ // or simply return the parent class error handling
30
+ return super.catch(err);
31
+ }
32
+ // istanbul ignore next
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ async finally(_) {
35
+ // called after execution and catching up, whether the command was wrong or not
36
+ return super.finally(_);
37
+ }
38
+ }
39
+ exports.BaseCommand = BaseCommand;
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Activity extends BaseCommand<typeof Activity> {
4
+ static description: string;
5
+ static examples: string[];
6
+ static flags: {
7
+ number: import("@oclif/core/lib/interfaces").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ };
10
+ catch(error: Error): Promise<void>;
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,75 @@
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 baseCommand_1 = require("../baseCommand");
7
+ const errors_1 = require("../errors");
8
+ const integrations_1 = require("../resources/integrations");
9
+ const GlobalConfiguration = tslib_1.__importStar(require("../resources/globalConfiguration"));
10
+ const IntegrationsPlatform = tslib_1.__importStar(require("../services/integrationsPlatform"));
11
+ const IntegrationConfiguration = tslib_1.__importStar(require("../resources/configuration"));
12
+ class Activity extends baseCommand_1.BaseCommand {
13
+ static description = 'Show the activity associated with your integration';
14
+ static examples = ['<%= config.bin %> <%= command.id %>'];
15
+ static flags = {
16
+ number: core_1.Flags.integer({
17
+ char: 'n',
18
+ summary: 'number of events to show',
19
+ description: `Limit the number of events to show. Must be less than or equal to 1000. Default is 1000.
20
+
21
+ Usage: <%= config.bin %> <%= command.id %> --number=10`,
22
+ }),
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
+ };
29
+ async catch(error) {
30
+ /* istanbul ignore if */
31
+ if ((0, errors_1.handleError)(error)) {
32
+ this.exit(-1);
33
+ }
34
+ throw error;
35
+ }
36
+ async run() {
37
+ (0, integrations_1.validateIsIntegrationDirectory)();
38
+ const { flags } = await this.parse(Activity);
39
+ // Read the configurations.
40
+ const globalConfiguration = await GlobalConfiguration.read(this.config.configDir);
41
+ const environment = flags.environment ?? GlobalConfiguration.Environment.Production;
42
+ const integrationConfiguration = await IntegrationConfiguration.getConfiguration(environment);
43
+ // Choose the right API key for the environment.
44
+ let apiKey = undefined;
45
+ if (environment === GlobalConfiguration.Environment.Local) {
46
+ apiKey = globalConfiguration.apiKeyLocal;
47
+ }
48
+ else if (environment === GlobalConfiguration.Environment.Staging) {
49
+ apiKey = globalConfiguration.apiKeyStaging;
50
+ }
51
+ else {
52
+ apiKey = globalConfiguration.apiKey;
53
+ }
54
+ // Setup the platform client.
55
+ IntegrationsPlatform.setApiKey(apiKey);
56
+ IntegrationsPlatform.setEnvironment(environment);
57
+ core_1.ux.action.start('Finding the integration');
58
+ const integration = await IntegrationsPlatform.getIntegrationByName(integrationConfiguration.name);
59
+ if (!integration) {
60
+ core_1.ux.log(chalk_1.default.redBright(`Integration not found! You can only retrieve activity for existing integrations.`));
61
+ this.exit(-1);
62
+ }
63
+ core_1.ux.action.stop();
64
+ core_1.ux.action.start('Retrieving activity');
65
+ const events = await IntegrationsPlatform.getIntegrationEvents(integration.id);
66
+ core_1.ux.action.stop();
67
+ for (const event of events.slice(0, flags.number ?? 1000)) {
68
+ core_1.ux.log();
69
+ core_1.ux.log(chalk_1.default.bold(` ${event.date} - ${event.title}`));
70
+ core_1.ux.log(` ${event.text}`);
71
+ core_1.ux.log(chalk_1.default.dim(chalk_1.default.italic(` ${event.tags.join(', ')}`)));
72
+ }
73
+ }
74
+ }
75
+ exports.default = Activity;
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../baseCommand';
2
+ import * as GlobalConfiguration from '../resources/globalConfiguration';
3
+ export default class Dev extends BaseCommand<typeof Dev> {
4
+ static description: string;
5
+ static examples: string[];
6
+ catch(error: Error): Promise<void>;
7
+ static flags: {
8
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<GlobalConfiguration.Environment | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ crawlMode: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ checks: import("@oclif/core/lib/interfaces").OptionFlag<string[], import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ 'config-path': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ };
14
+ run(): Promise<void>;
15
+ }