@itentialopensource/adapter-jira 1.7.4 → 1.7.6

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 (183) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +9587 -0
  4. package/CHANGELOG.md +16 -0
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +225 -502
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +10821 -59
  14. package/adapterBase.js +1030 -248
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/entities/Avatars/action.json +63 -0
  18. package/entities/Avatars/schema.json +4 -1
  19. package/entities/Dashboards/action.json +80 -0
  20. package/entities/Dashboards/mockdatafiles/copyDashboard-default.json +13 -0
  21. package/entities/Dashboards/mockdatafiles/createDashboard-default.json +13 -0
  22. package/entities/Dashboards/mockdatafiles/updateDashboard-default.json +13 -0
  23. package/entities/Dashboards/schema.json +5 -1
  24. package/entities/Groups/action.json +21 -0
  25. package/entities/Groups/mockdatafiles/bulkGetGroups-default.json +16 -0
  26. package/entities/Groups/schema.json +2 -1
  27. package/entities/InstanceInformation/action.json +25 -0
  28. package/entities/InstanceInformation/mockdatafiles/getLicense-default.json +20 -0
  29. package/entities/InstanceInformation/schema.json +19 -0
  30. package/entities/IssueCustomFieldConfigurationApps/action.json +45 -0
  31. package/entities/IssueCustomFieldConfigurationApps/mockdatafiles/getCustomFieldConfiguration-default.json +34 -0
  32. package/entities/IssueCustomFieldConfigurationApps/schema.json +20 -0
  33. package/entities/IssueCustomFieldContexts/action.json +268 -0
  34. package/entities/IssueCustomFieldContexts/mockdatafiles/createCustomFieldContext-default.json +9 -0
  35. package/entities/IssueCustomFieldContexts/mockdatafiles/getContextsForField-default.json +22 -0
  36. package/entities/IssueCustomFieldContexts/mockdatafiles/getCustomFieldContextsForProjectsAndIssueTypes-default.json +23 -0
  37. package/entities/IssueCustomFieldContexts/mockdatafiles/getDefaultValues-default.json +22 -0
  38. package/entities/IssueCustomFieldContexts/mockdatafiles/getIssueTypeMappingsForContexts-default.json +20 -0
  39. package/entities/IssueCustomFieldContexts/mockdatafiles/getProjectContextMapping-default.json +16 -0
  40. package/entities/IssueCustomFieldContexts/schema.json +31 -0
  41. package/entities/IssueCustomFieldOptions/action.json +105 -0
  42. package/entities/IssueCustomFieldOptions/mockdatafiles/createCustomFieldOption-default.json +20 -0
  43. package/entities/IssueCustomFieldOptions/mockdatafiles/getOptionsForContext-default.json +26 -0
  44. package/entities/IssueCustomFieldOptions/mockdatafiles/updateCustomFieldOption-default.json +19 -0
  45. package/entities/IssueCustomFieldOptions/schema.json +23 -0
  46. package/entities/IssueCustomFieldValuesApps/action.json +44 -0
  47. package/entities/IssueCustomFieldValuesApps/schema.json +20 -0
  48. package/entities/IssueFieldConfigurations/action.json +309 -0
  49. package/entities/IssueFieldConfigurations/mockdatafiles/createFieldConfiguration-default.json +5 -0
  50. package/entities/IssueFieldConfigurations/mockdatafiles/createFieldConfigurationScheme-default.json +5 -0
  51. package/entities/IssueFieldConfigurations/mockdatafiles/getAllFieldConfigurationSchemes-default.json +23 -0
  52. package/entities/IssueFieldConfigurations/mockdatafiles/getAllFieldConfigurations-default.json +19 -0
  53. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationItems-default.json +19 -0
  54. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationSchemeMappings-default.json +33 -0
  55. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationSchemeProjectMapping-default.json +26 -0
  56. package/entities/IssueFieldConfigurations/schema.json +33 -0
  57. package/entities/IssueTypeSchemes/action.json +207 -0
  58. package/entities/IssueTypeSchemes/mockdatafiles/createIssueTypeScheme-default.json +3 -0
  59. package/entities/IssueTypeSchemes/mockdatafiles/getAllIssueTypeSchemes-default.json +26 -0
  60. package/entities/IssueTypeSchemes/mockdatafiles/getIssueTypeSchemeForProjects-default.json +44 -0
  61. package/entities/IssueTypeSchemes/mockdatafiles/getIssueTypeSchemesMapping-default.json +24 -0
  62. package/entities/IssueTypeSchemes/schema.json +28 -0
  63. package/entities/IssueTypeScreenSchemes/action.json +228 -0
  64. package/entities/IssueTypeScreenSchemes/mockdatafiles/createIssueTypeScreenScheme-default.json +3 -0
  65. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemeMappings-default.json +28 -0
  66. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemeProjectAssociations-default.json +19 -0
  67. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemes-default.json +18 -0
  68. package/entities/IssueTypeScreenSchemes/mockdatafiles/getProjectsForIssueTypeScreenScheme-default.json +27 -0
  69. package/entities/IssueTypeScreenSchemes/schema.json +29 -0
  70. package/entities/Issueattachments/action.json +42 -0
  71. package/entities/Issueattachments/schema.json +3 -1
  72. package/entities/Issuefields/action.json +122 -0
  73. package/entities/Issuefields/mockdatafiles/getContextsForFieldDeprecated-default.json +12 -0
  74. package/entities/Issuefields/mockdatafiles/getFieldsPaginated-default.json +46 -0
  75. package/entities/Issuefields/schema.json +7 -1
  76. package/entities/Issueproperties/action.json +40 -0
  77. package/entities/Issueproperties/schema.json +3 -1
  78. package/entities/Issues/action.json +45 -0
  79. package/entities/Issues/mockdatafiles/getChangeLogsByIds-default.json +65 -0
  80. package/entities/Issues/mockdatafiles/getEvents-default.json +10 -0
  81. package/entities/Issues/schema.json +20 -0
  82. package/entities/Issuesearch/action.json +20 -0
  83. package/entities/Issuesearch/mockdatafiles/matchIssues-default.json +29 -0
  84. package/entities/Issuesearch/schema.json +2 -1
  85. package/entities/Issuesecuritylevel/action.json +21 -0
  86. package/entities/Issuesecuritylevel/mockdatafiles/getIssueSecurityLevelMembers-default.json +46 -0
  87. package/entities/Issuesecuritylevel/schema.json +2 -1
  88. package/entities/Issuetypes/action.json +21 -0
  89. package/entities/Issuetypes/mockdatafiles/getIssueTypesForProject-default.json +39 -0
  90. package/entities/Issuetypes/schema.json +2 -1
  91. package/entities/Issuewatchers/action.json +20 -0
  92. package/entities/Issuewatchers/mockdatafiles/getIsWatchingIssueBulk-default.json +7 -0
  93. package/entities/Issuewatchers/schema.json +2 -1
  94. package/entities/JQL/action.json +40 -0
  95. package/entities/JQL/mockdatafiles/getAutoCompletePost-default.json +89 -0
  96. package/entities/JQL/mockdatafiles/parseJqlQueries-default.json +119 -0
  97. package/entities/JQL/schema.json +3 -1
  98. package/entities/Jiraexpressions/action.json +20 -0
  99. package/entities/Jiraexpressions/mockdatafiles/analyseExpression-default.json +47 -0
  100. package/entities/Jiraexpressions/schema.json +2 -1
  101. package/entities/Labels/action.json +25 -0
  102. package/entities/Labels/mockdatafiles/getAllLabels-default.json +10 -0
  103. package/entities/Labels/schema.json +19 -0
  104. package/entities/ProjectEmail/action.json +45 -0
  105. package/entities/ProjectEmail/mockdatafiles/getProjectEmail-default.json +6 -0
  106. package/entities/ProjectEmail/schema.json +20 -0
  107. package/entities/ProjectFeatures/action.json +45 -0
  108. package/entities/ProjectFeatures/mockdatafiles/getFeaturesForProject-default.json +24 -0
  109. package/entities/ProjectFeatures/mockdatafiles/toggleFeatureForProject-default.json +24 -0
  110. package/entities/ProjectFeatures/schema.json +20 -0
  111. package/entities/Projects/action.json +102 -0
  112. package/entities/Projects/mockdatafiles/getHierarchy-default.json +50 -0
  113. package/entities/Projects/mockdatafiles/getRecent-default.json +50 -0
  114. package/entities/Projects/mockdatafiles/restore-default.json +139 -0
  115. package/entities/Projects/schema.json +6 -1
  116. package/entities/Projecttypes/action.json +21 -0
  117. package/entities/Projecttypes/mockdatafiles/getAllAccessibleProjectTypes-default.json +16 -0
  118. package/entities/Projecttypes/schema.json +2 -1
  119. package/entities/ScreenSchemes/action.json +85 -0
  120. package/entities/ScreenSchemes/mockdatafiles/createScreenScheme-default.json +3 -0
  121. package/entities/ScreenSchemes/mockdatafiles/getScreenSchemes-default.json +28 -0
  122. package/entities/ScreenSchemes/schema.json +22 -0
  123. package/entities/Screens/action.json +81 -0
  124. package/entities/Screens/mockdatafiles/createScreen-default.json +5 -0
  125. package/entities/Screens/mockdatafiles/getScreensForField-default.json +17 -0
  126. package/entities/Screens/mockdatafiles/updateScreen-default.json +5 -0
  127. package/entities/Screens/schema.json +5 -1
  128. package/entities/Users/action.json +84 -0
  129. package/entities/Users/mockdatafiles/getAllUsers-default.json +32 -0
  130. package/entities/Users/mockdatafiles/getAllUsersDefault-default.json +32 -0
  131. package/entities/Users/mockdatafiles/getUserEmail-default.json +1 -0
  132. package/entities/Users/schema.json +5 -1
  133. package/entities/Webhooks/action.json +106 -0
  134. package/entities/Webhooks/mockdatafiles/getDynamicWebhooksForApp-default.json +40 -0
  135. package/entities/Webhooks/mockdatafiles/getFailedWebhooks-default.json +17 -0
  136. package/entities/Webhooks/mockdatafiles/refreshWebhooks-default.json +3 -0
  137. package/entities/Webhooks/mockdatafiles/registerDynamicWebhooks-default.json +15 -0
  138. package/entities/Webhooks/schema.json +23 -0
  139. package/entities/WorkflowSchemeProjectAssociations/action.json +45 -0
  140. package/entities/WorkflowSchemeProjectAssociations/mockdatafiles/getWorkflowSchemeProjectAssociations-default.json +21 -0
  141. package/entities/WorkflowSchemeProjectAssociations/schema.json +20 -0
  142. package/entities/WorkflowTransitionRules/action.json +65 -0
  143. package/entities/WorkflowTransitionRules/mockdatafiles/deleteWorkflowTransitionRuleConfigurations-default.json +34 -0
  144. package/entities/WorkflowTransitionRules/mockdatafiles/getWorkflowTransitionRuleConfigurations-default.json +56 -0
  145. package/entities/WorkflowTransitionRules/mockdatafiles/updateWorkflowTransitionRuleConfigurations-default.json +34 -0
  146. package/entities/WorkflowTransitionRules/schema.json +21 -0
  147. package/entities/Workflows/action.json +61 -0
  148. package/entities/Workflows/mockdatafiles/createWorkflow-default.json +4 -0
  149. package/entities/Workflows/mockdatafiles/getWorkflowsPaginated-default.json +140 -0
  150. package/entities/Workflows/schema.json +4 -1
  151. package/entities/Workflowschemedrafts/action.json +20 -0
  152. package/entities/Workflowschemedrafts/schema.json +2 -1
  153. package/entities/Workflowschemes/action.json +21 -0
  154. package/entities/Workflowschemes/mockdatafiles/getAllWorkflowSchemes-default.json +30 -0
  155. package/entities/Workflowschemes/schema.json +2 -1
  156. package/error.json +12 -0
  157. package/package.json +21 -13
  158. package/pronghorn.json +33339 -5948
  159. package/propertiesDecorators.json +14 -0
  160. package/propertiesSchema.json +436 -0
  161. package/refs?service=git-upload-pack +0 -0
  162. package/report/adapterInfo.json +10 -0
  163. package/report/updateReport1659707107792.json +120 -0
  164. package/sampleProperties.json +95 -3
  165. package/test/integration/adapterTestBasicGet.js +2 -2
  166. package/test/integration/adapterTestIntegration.js +3633 -106
  167. package/test/unit/adapterBaseTestUnit.js +35 -27
  168. package/test/unit/adapterTestUnit.js +4767 -115
  169. package/utils/adapterInfo.js +206 -0
  170. package/utils/addAuth.js +94 -0
  171. package/utils/basicGet.js +1 -14
  172. package/utils/entitiesToDB.js +179 -0
  173. package/utils/methodDocumentor.js +225 -0
  174. package/utils/modify.js +1 -1
  175. package/utils/packModificationScript.js +1 -1
  176. package/utils/patches2bundledDeps.js +90 -0
  177. package/utils/pre-commit.sh +5 -0
  178. package/utils/removeHooks.js +20 -0
  179. package/utils/tbScript.js +43 -22
  180. package/utils/tbUtils.js +126 -29
  181. package/utils/testRunner.js +16 -16
  182. package/utils/troubleshootingAdapter.js +2 -26
  183. package/versions.json +142 -0
@@ -0,0 +1,225 @@
1
+ /* eslint global-require:warn */
2
+ /* eslint import/no-dynamic-require:warn */
3
+ /* eslint no-param-reassign:warn */
4
+
5
+ const fs = require('fs-extra');
6
+ const esprima = require('esprima');
7
+
8
+ // Getting the base directory:
9
+ let adaptdir = __dirname;
10
+ if (adaptdir.endsWith('/utils')) {
11
+ adaptdir = adaptdir.substring(0, adaptdir.length - 6);
12
+ }
13
+
14
+ function createObjectForFunction(
15
+ funcName,
16
+ funcArgs,
17
+ entityPath,
18
+ description,
19
+ workflow
20
+ ) {
21
+ const funcObject = {};
22
+ // if the entity path is not set, then the object is not created.
23
+ if (entityPath !== undefined) {
24
+ funcObject.method_signature = `${funcName}(${funcArgs.join(', ')})`;
25
+ funcObject.path = entityPath;
26
+ if (description === undefined) {
27
+ funcObject.description = '';
28
+ funcObject.workflow = 'No';
29
+ } else {
30
+ funcObject.description = description;
31
+ funcObject.workflow = workflow;
32
+ }
33
+ }
34
+ return funcObject;
35
+ }
36
+
37
+ function getPathFromEntity(entity, funcName) {
38
+ let epath;
39
+ if (entity === undefined || entity === '.generic') {
40
+ epath = undefined;
41
+ } else {
42
+ // Access the action.js file for the certain entity to get the path
43
+ const entityPath = `${adaptdir}/entities/${entity}/action.json`;
44
+ const actionJSON = require(entityPath);
45
+ actionJSON.actions.forEach((action) => {
46
+ if (action.name === funcName) {
47
+ epath = action.entitypath;
48
+ }
49
+ });
50
+ }
51
+ return epath;
52
+ }
53
+
54
+ function readFileUsingLib(filename, descriptionObj, workflowObj, functionList) {
55
+ // read the file
56
+ const aFile = fs.readFileSync(filename, 'utf8');
57
+ // parsing the file to get the function and class declarations.
58
+ const aFileFuncArgs = esprima.parseScript(aFile);
59
+
60
+ // Looping through all the declarations parsed:
61
+ aFileFuncArgs.body.forEach((e) => {
62
+ // Getting only the class declaration as it has our required functions.
63
+ if (e.type === 'ClassDeclaration') {
64
+ const methodDefinition = e.body;
65
+ methodDefinition.body.forEach((method) => {
66
+ // Getting method name and its params in the class.
67
+ const funcName = method.key.name;
68
+ const funcArgs = [];
69
+ method.value.params.forEach((param) => {
70
+ if (param.type === 'Identifier') {
71
+ funcArgs.push(param.name);
72
+ } else {
73
+ const args = `${param.left.name} = ${param.right.value}`;
74
+ funcArgs.push(args);
75
+ }
76
+ });
77
+
78
+ // Getting the entity for the method:
79
+ let entity;
80
+ method.value.body.body.forEach((statementType) => {
81
+ if (statementType.type === 'TryStatement') {
82
+ entity = statementType.block.body[0].argument.arguments[0].value;
83
+ }
84
+ });
85
+ const entityPath = getPathFromEntity(entity, funcName);
86
+
87
+ // Creating and storing the object for the method.
88
+ if (entityPath !== undefined) {
89
+ functionList.push(
90
+ createObjectForFunction(
91
+ funcName,
92
+ funcArgs,
93
+ entityPath,
94
+ descriptionObj[funcName],
95
+ workflowObj[funcName]
96
+ )
97
+ );
98
+ }
99
+ });
100
+ }
101
+ });
102
+ }
103
+
104
+ function readJSONFile(filename, descriptionObj, workflowObj) {
105
+ // Accessing the JSON file.
106
+ const phJSON = require(filename);
107
+ // Getting the methods array.
108
+ const methodArray = phJSON.methods;
109
+ methodArray.forEach((methodName) => {
110
+ // Getting the method description and workflow:
111
+ const funcName = methodName.name;
112
+ descriptionObj[funcName] = methodName.description;
113
+ workflowObj[funcName] = methodName.task ? 'Yes' : 'No';
114
+ });
115
+ }
116
+
117
+ function readMDFile(filename, functionList) {
118
+ // Reading in the .md file and creating an array with each line as an element.
119
+ const mdFile = fs.readFileSync(filename, 'utf-8');
120
+ const fileSplit = mdFile.split('\n');
121
+ // Storing the data that should added later to the updated data.
122
+ const linesToAddLater = [];
123
+ let index = fileSplit.length - 1;
124
+
125
+ // Removing all the blank lines at the end of the file.
126
+ if (fileSplit[index] === '') {
127
+ while (fileSplit[index] === '') {
128
+ linesToAddLater.push(fileSplit.pop());
129
+ index -= 1;
130
+ }
131
+ }
132
+
133
+ // Checking if the last 2 lines are <br> and </table>. If not, the file is corrupted and the
134
+ // data at the end of the file should be fixed.
135
+ if (fileSplit[index] === '<br>' || fileSplit[index - 1] === '</table>') {
136
+ // Storing <br> and </table> to add later.
137
+ linesToAddLater.push(fileSplit.pop());
138
+ linesToAddLater.push(fileSplit.pop());
139
+ index -= 2;
140
+ } else {
141
+ console.log('The file has bad content at the end.');
142
+ return;
143
+ }
144
+ // if (fileSplit[index] !== '<br>' && fileSplit[index - 1] !== '</table>') {
145
+ // console.log('The file has bad content at the end.');
146
+ // return;
147
+ // } else {
148
+ // // Storing <br> and </table> to add later.
149
+ // linesToAddLater.push(fileSplit.pop());
150
+ // linesToAddLater.push(fileSplit.pop());
151
+ // index -= 2;
152
+ // }
153
+
154
+ // Removing all the lines until the header tags are reached.
155
+ while (!fileSplit[index].includes('<th')) {
156
+ fileSplit.pop();
157
+ index -= 1;
158
+ }
159
+ // Adding </tr> for the header row, because it got removed in the above loop.
160
+ fileSplit.push(' </tr>');
161
+
162
+ // Creating the tags for each method to be appended to the file.
163
+ const tdBeginTag = ' <td style="padding:15px">';
164
+ const tdEndTag = '</td>';
165
+ functionList.forEach((func) => {
166
+ const signCommand = `${tdBeginTag}${func.method_signature}${tdEndTag}`;
167
+ const descCommand = `${tdBeginTag}${func.description}${tdEndTag}`;
168
+ const pathCommand = `${tdBeginTag}${func.path}${tdEndTag}`;
169
+ const workflowCommand = `${tdBeginTag}${func.workflow}${tdEndTag}`;
170
+ fileSplit.push(' <tr>');
171
+ fileSplit.push(signCommand);
172
+ fileSplit.push(descCommand);
173
+ fileSplit.push(pathCommand);
174
+ fileSplit.push(workflowCommand);
175
+ fileSplit.push(' </tr>');
176
+ });
177
+
178
+ // Adding </table> and <br> at the end of the file to complete the table and the file.
179
+ while (linesToAddLater.length > 0) {
180
+ fileSplit.push(linesToAddLater.pop());
181
+ }
182
+
183
+ // Writing all the content back into the file.
184
+ fs.writeFileSync(filename, fileSplit.join('\n'), {
185
+ encoding: 'utf-8',
186
+ flag: 'w'
187
+ });
188
+ }
189
+
190
+ function getFileInfo() {
191
+ // If files don't exist:
192
+ if (!fs.existsSync(`${adaptdir}/adapter.js`)) {
193
+ console.log('Missing - utils/adapter.js');
194
+ return;
195
+ }
196
+ if (!fs.existsSync(`${adaptdir}/pronghorn.json`)) {
197
+ console.log('Missing - pronghorn.json');
198
+ return;
199
+ }
200
+ if (!fs.existsSync(`${adaptdir}/CALLS.md`)) {
201
+ console.log('Missing - CALLS.md');
202
+ return;
203
+ }
204
+
205
+ const descriptionObj = {};
206
+ const workflowObj = {};
207
+
208
+ // Get the method descriptions and the workflow values from pronghorn.json file.
209
+ readJSONFile(`${adaptdir}/pronghorn.json`, descriptionObj, workflowObj);
210
+
211
+ // Get the method signature, entity path and create an object that contains all the info regarding
212
+ // the method and push it to the functionList array.
213
+ const functionList = [];
214
+ readFileUsingLib(
215
+ `${adaptdir}/adapter.js`,
216
+ descriptionObj,
217
+ workflowObj,
218
+ functionList
219
+ );
220
+
221
+ // createMarkDown(functionList);
222
+ readMDFile(`${adaptdir}/CALLS.md`, functionList);
223
+ }
224
+
225
+ getFileInfo();
package/utils/modify.js CHANGED
@@ -3,7 +3,7 @@ const Ajv = require('ajv');
3
3
  const rls = require('readline-sync');
4
4
  const { execSync } = require('child_process');
5
5
  const { existsSync } = require('fs-extra');
6
- const { getAdapterConfig } = require('./troubleshootingAdapter');
6
+ const { getAdapterConfig } = require('./tbUtils');
7
7
  const { name } = require('../package.json');
8
8
  const propertiesSchema = require('../propertiesSchema.json');
9
9
 
@@ -4,7 +4,7 @@
4
4
  const fs = require('fs-extra');
5
5
  const path = require('path');
6
6
  const { spawnSync } = require('child_process');
7
- const { createBundle } = require('./artifactize.js');
7
+ const { createBundle } = require('./artifactize');
8
8
 
9
9
  const nodeEntryPath = path.resolve('.');
10
10
  createBundle(nodeEntryPath).then((pathObj) => {
@@ -0,0 +1,90 @@
1
+ const fs = require('fs');
2
+ const semverSatisfies = require('semver/functions/satisfies');
3
+ const packageJson = require('../package.json');
4
+
5
+ try {
6
+ // pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
7
+ // const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
8
+ // pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
9
+ // removed P's from before capturing group names and
10
+ // removed gm from end to only match a single semver
11
+ // const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
12
+
13
+ const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
14
+ if (!patches.length) {
15
+ console.error('\nno patches - nothing to do\n');
16
+ process.exitCode = 1;
17
+ }
18
+
19
+ const dependencies = packageJson.dependencies || {};
20
+ if (!Object.keys(dependencies).length) {
21
+ console.error('\nno dependencies - nothing to do\n');
22
+ process.exitCode = 1;
23
+ }
24
+
25
+ let changed = false;
26
+ console.error('\nprocessing patches');
27
+ const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
28
+
29
+ patches.forEach((patch) => {
30
+ if (!patch.isFile()) {
31
+ console.error(`${patch.name} skipped, is not a regular file`);
32
+ return;
33
+ }
34
+ if (!patch.name.endsWith('.patch')) {
35
+ console.error(`${patch.name} skipped, does not end with .patch`);
36
+ return;
37
+ }
38
+ const splits = patch.name.slice(0, -6).split('+');
39
+ if (splits.length > 4) {
40
+ console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
41
+ return;
42
+ }
43
+ const scope = splits[0][0] === '@' ? splits.shift() : null;
44
+ const packageName = splits.shift();
45
+ const semver = splits.join('+');
46
+ // const { groups } = semver.match(semverPat);
47
+ const file = scope ? `${scope}/${packageName}` : packageName;
48
+ if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
49
+ if (!bundledDependencies.includes(file)) {
50
+ bundledDependencies.push(file);
51
+ console.error(`added ${file} to bundledDependencies`);
52
+ changed = true;
53
+ } else {
54
+ console.error(`bundledDependencies already has ${file}`);
55
+ }
56
+ } else {
57
+ const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
58
+ console.error(`patch ${patch.name} ${depmsg}`);
59
+ }
60
+ });
61
+
62
+ if (!packageJson.bundledDependencies && bundledDependencies.length) {
63
+ delete packageJson.bundleDependencies;
64
+ packageJson.bundledDependencies = bundledDependencies;
65
+ console.error('renaming bundleDependencies to bundledDependencies');
66
+ changed = true;
67
+ }
68
+ if (changed) {
69
+ fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
70
+ console.error('wrote package.json.new');
71
+ fs.renameSync('./package.json', './package.json.old');
72
+ console.error('moved package.json to package.json.old');
73
+ fs.renameSync('./package.json.new', './package.json');
74
+ console.error('moved package.json.new to package.json');
75
+ } else {
76
+ console.error('no changes\n');
77
+ process.exitCode = 1;
78
+ }
79
+ } catch (e) {
80
+ if (e) {
81
+ // caught error, exit with status 2 to signify abject failure
82
+ console.error(`\ncaught exception - ${e}\n`);
83
+ process.exitCode = 2;
84
+ } else {
85
+ // caught false, exit with status 1 to signify nothing done
86
+ process.exitCode = 1;
87
+ }
88
+ } finally {
89
+ console.error('done\n');
90
+ }
@@ -17,6 +17,11 @@ printf "%b" "Running pre-commit hooks...\\n"
17
17
  # verify testing script is stubbed and no credentials
18
18
  node utils/testRunner.js -r
19
19
 
20
+ # update the adapter information file
21
+ node utils/adapterInfo.js
22
+ node utils/methodDocumentor.js
23
+ git add CALLS.md utils/methodDocumentor.js
24
+
20
25
  # security audit on the code
21
26
  npm audit --registry=https://registry.npmjs.org --audit-level=moderate
22
27
 
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+
3
+ /**
4
+ * This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
5
+ * commit/push something that has issues
6
+ */
7
+
8
+ const precommitPath = '.git/hooks/pre-commit';
9
+ const prepushPath = '.git/hooks/pre-push';
10
+ fs.unlink(precommitPath, (err) => {
11
+ if (err && err.code !== 'ENOENT') {
12
+ console.log(`${err.message}`);
13
+ }
14
+ });
15
+
16
+ fs.unlink(prepushPath, (err) => {
17
+ if (err && err.code !== 'ENOENT') {
18
+ console.log(`${err.message}`);
19
+ }
20
+ });
package/utils/tbScript.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint no-console: warn */
1
+ /* eslint-disable no-console */
2
2
  /* eslint import/no-unresolved: warn */
3
3
  /* eslint global-require: warn */
4
4
 
@@ -7,7 +7,6 @@
7
7
  /* eslint import/no-extraneous-dependencies: warn */
8
8
  /* eslint import/no-dynamic-require: warn */
9
9
 
10
- const path = require('path');
11
10
  const program = require('commander');
12
11
  const rls = require('readline-sync');
13
12
  const utils = require('./tbUtils');
@@ -15,35 +14,47 @@ const basicGet = require('./basicGet');
15
14
  const { name } = require('../package.json');
16
15
  const sampleProperties = require('../sampleProperties.json');
17
16
  const adapterPronghorn = require('../pronghorn.json');
17
+ const { addAuthInfo } = require('./addAuth');
18
18
 
19
- const { troubleshoot, getAdapterConfig, offline } = require('./troubleshootingAdapter');
19
+ const { troubleshoot, offline } = require('./troubleshootingAdapter');
20
20
 
21
- const main = async (command) => {
22
- const iapDir = path.join(__dirname, '../../../../');
23
- if (!utils.withinIAP(iapDir)) {
24
- if (command === 'connectivity') {
21
+ const executeInStandaloneMode = async (command) => {
22
+ console.info('\n> Executing the script outside of IAP installation directory');
23
+ console.info('> Using sampleProperties.json configuration');
24
+ switch (command) {
25
+ case 'install': {
26
+ console.error('Not currently in IAP directory - installation not possible');
27
+ break;
28
+ }
29
+ case 'connectivity': {
25
30
  const { host } = sampleProperties.properties;
26
31
  console.log(`perform networking diagnositics to ${host}`);
27
- await utils.runConnectivity(host);
28
- process.exit(0);
29
- } else if (command === 'healthcheck') {
32
+ utils.runConnectivity(host);
33
+ break;
34
+ }
35
+ case 'healthcheck': {
30
36
  const a = basicGet.getAdapterInstance({ properties: sampleProperties });
31
37
  await utils.healthCheck(a);
32
- process.exit(0);
33
- } else if (command === 'basicget') {
34
- await utils.runBasicGet();
35
- process.exit(0);
38
+ break;
39
+ }
40
+ case 'basicget': {
41
+ utils.runBasicGet();
42
+ break;
36
43
  }
37
- if (rls.keyInYN('Troubleshooting without IAP?')) {
38
- await offline();
44
+ default: {
45
+ if (rls.keyInYN('Troubleshooting without IAP?')) {
46
+ await offline();
47
+ }
39
48
  }
40
- process.exit(0);
41
49
  }
50
+ process.exit(0);
51
+ };
42
52
 
53
+ const executeUnderIAPInstallationDirectory = async (command) => {
43
54
  if (command === undefined) {
44
55
  await troubleshoot({}, true, true);
45
56
  } else if (command === 'install') {
46
- const { database, serviceItem, pronghornProps } = await getAdapterConfig();
57
+ const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
47
58
  const filter = { id: pronghornProps.id };
48
59
  const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
49
60
  if (!profileItem) {
@@ -74,14 +85,17 @@ const main = async (command) => {
74
85
  process.exit(0);
75
86
  }
76
87
  } else {
77
- utils.verifyInstallationDir(__dirname, name);
78
- utils.npmInstall();
88
+ const dirname = utils.getCurrentExecutionPath();
89
+ utils.verifyInstallationDir(dirname, name);
79
90
  utils.runTest();
80
91
  if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
81
92
  console.log('Creating database entries...');
82
93
  const adapter = utils.createAdapter(
83
94
  pronghornProps, profileItem, sampleProperties, adapterPronghorn
84
95
  );
96
+
97
+ adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
98
+
85
99
  await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
86
100
  profileItem.services.push(adapter.name);
87
101
  const update = { $set: { services: profileItem.services } };
@@ -94,7 +108,7 @@ const main = async (command) => {
94
108
  process.exit(0);
95
109
  }
96
110
  } else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
97
- const { serviceItem } = await getAdapterConfig();
111
+ const { serviceItem } = await utils.getAdapterConfig();
98
112
  if (serviceItem) {
99
113
  const adapter = serviceItem;
100
114
  const a = basicGet.getAdapterInstance(adapter);
@@ -116,6 +130,14 @@ const main = async (command) => {
116
130
  }
117
131
  };
118
132
 
133
+ const main = async (command) => {
134
+ if (!utils.areWeUnderIAPinstallationDirectory()) {
135
+ executeInStandaloneMode(command); // configuration from sampleproperties.json
136
+ } else {
137
+ executeUnderIAPInstallationDirectory(command); // configuration from $IAP_HOME/properties.json
138
+ }
139
+ };
140
+
119
141
  program
120
142
  .command('connectivity')
121
143
  .alias('c')
@@ -154,7 +176,6 @@ program.parse(process.argv);
154
176
  if (process.argv.length < 3) {
155
177
  main();
156
178
  }
157
-
158
179
  const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
159
180
  if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
160
181
  console.log(`unknown parameter ${process.argv[2]}`);