@itentialopensource/adapter-sendgrid 0.1.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.
- package/.eslintignore +5 -0
- package/.eslintrc.js +18 -0
- package/.jshintrc +3 -0
- package/AUTH.md +31 -0
- package/BROKER.md +211 -0
- package/CALLS.md +2211 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +13 -0
- package/ENHANCE.md +69 -0
- package/LICENSE +201 -0
- package/PROPERTIES.md +646 -0
- package/README.md +343 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +20 -0
- package/TAB1.md +11 -0
- package/TAB2.md +302 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +38033 -0
- package/adapterBase.js +1452 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/APIKeyPermissions/action.json +25 -0
- package/entities/APIKeyPermissions/schema.json +19 -0
- package/entities/APIKeys/action.json +126 -0
- package/entities/APIKeys/schema.json +35 -0
- package/entities/Alerts/action.json +106 -0
- package/entities/Alerts/schema.json +34 -0
- package/entities/BlocksAPI/action.json +86 -0
- package/entities/BlocksAPI/schema.json +44 -0
- package/entities/BouncesAPI/action.json +86 -0
- package/entities/BouncesAPI/schema.json +55 -0
- package/entities/CSVUIOnly/action.json +45 -0
- package/entities/CSVUIOnly/schema.json +31 -0
- package/entities/CampaignsAPI/action.json +227 -0
- package/entities/CampaignsAPI/schema.json +40 -0
- package/entities/CancelScheduledSends/action.json +147 -0
- package/entities/CancelScheduledSends/schema.json +36 -0
- package/entities/Categories/action.json +67 -0
- package/entities/Categories/schema.json +76 -0
- package/entities/Certificates/action.json +106 -0
- package/entities/Certificates/schema.json +45 -0
- package/entities/Contacts/action.json +270 -0
- package/entities/Contacts/schema.json +42 -0
- package/entities/ContactsAPICustomFields/action.json +107 -0
- package/entities/ContactsAPICustomFields/schema.json +34 -0
- package/entities/ContactsAPILists/action.json +207 -0
- package/entities/ContactsAPILists/schema.json +72 -0
- package/entities/ContactsAPIRecipients/action.json +251 -0
- package/entities/ContactsAPIRecipients/schema.json +63 -0
- package/entities/ContactsAPISegments/action.json +127 -0
- package/entities/ContactsAPISegments/schema.json +57 -0
- package/entities/CustomFields/action.json +85 -0
- package/entities/CustomFields/schema.json +33 -0
- package/entities/DesignsAPI/action.json +188 -0
- package/entities/DesignsAPI/schema.json +49 -0
- package/entities/DomainAuthentication/action.json +248 -0
- package/entities/DomainAuthentication/schema.json +52 -0
- package/entities/EmailAddressValidation/action.json +24 -0
- package/entities/EmailAddressValidation/schema.json +19 -0
- package/entities/EmailCNAMERecords/action.json +24 -0
- package/entities/EmailCNAMERecords/schema.json +19 -0
- package/entities/IPAccessManagement/action.json +127 -0
- package/entities/IPAccessManagement/schema.json +35 -0
- package/entities/IPAddresses/action.json +108 -0
- package/entities/IPAddresses/schema.json +56 -0
- package/entities/IPPools/action.json +146 -0
- package/entities/IPPools/schema.json +36 -0
- package/entities/IPWarmup/action.json +86 -0
- package/entities/IPWarmup/schema.json +33 -0
- package/entities/InvalidEmailsAPI/action.json +86 -0
- package/entities/InvalidEmailsAPI/schema.json +44 -0
- package/entities/LinkBranding/action.json +208 -0
- package/entities/LinkBranding/schema.json +39 -0
- package/entities/Lists/action.json +147 -0
- package/entities/Lists/schema.json +80 -0
- package/entities/MailSend/action.json +24 -0
- package/entities/MailSend/schema.json +19 -0
- package/entities/MarketingCampaignsStats/action.json +172 -0
- package/entities/MarketingCampaignsStats/schema.json +147 -0
- package/entities/Query/action.json +46 -0
- package/entities/Query/schema.json +31 -0
- package/entities/ReverseDNS/action.json +106 -0
- package/entities/ReverseDNS/schema.json +23 -0
- package/entities/SegmentingContacts/action.json +126 -0
- package/entities/SegmentingContacts/schema.json +68 -0
- package/entities/SegmentingContactsV2/action.json +86 -0
- package/entities/SegmentingContactsV2/schema.json +66 -0
- package/entities/SegmentingContactsV2Beta/action.json +24 -0
- package/entities/SegmentingContactsV2Beta/schema.json +30 -0
- package/entities/SendTestEmail/action.json +24 -0
- package/entities/SendTestEmail/schema.json +19 -0
- package/entities/SenderIdentitiesAPI/action.json +126 -0
- package/entities/SenderIdentitiesAPI/schema.json +35 -0
- package/entities/SenderVerification/action.json +168 -0
- package/entities/SenderVerification/schema.json +26 -0
- package/entities/Senders/action.json +24 -0
- package/entities/Senders/schema.json +19 -0
- package/entities/SettingsEnforcedTLS/action.json +45 -0
- package/entities/SettingsEnforcedTLS/schema.json +20 -0
- package/entities/SettingsInboundParse/action.json +85 -0
- package/entities/SettingsInboundParse/schema.json +22 -0
- package/entities/SettingsMail/action.json +271 -0
- package/entities/SettingsMail/schema.json +31 -0
- package/entities/SettingsPartner/action.json +66 -0
- package/entities/SettingsPartner/schema.json +21 -0
- package/entities/SettingsTracking/action.json +189 -0
- package/entities/SettingsTracking/schema.json +27 -0
- package/entities/SingleSends/action.json +227 -0
- package/entities/SingleSends/schema.json +51 -0
- package/entities/SingleSignOnSettings/action.json +106 -0
- package/entities/SingleSignOnSettings/schema.json +23 -0
- package/entities/SingleSignOnTeammates/action.json +44 -0
- package/entities/SingleSignOnTeammates/schema.json +20 -0
- package/entities/SpamReportsAPI/action.json +86 -0
- package/entities/SpamReportsAPI/schema.json +44 -0
- package/entities/Stats/action.json +151 -0
- package/entities/Stats/schema.json +80 -0
- package/entities/SubuserMonitorSettings/action.json +85 -0
- package/entities/SubuserMonitorSettings/schema.json +33 -0
- package/entities/SubuserStatistics/action.json +88 -0
- package/entities/SubuserStatistics/schema.json +88 -0
- package/entities/SubusersAPI/action.json +126 -0
- package/entities/SubusersAPI/schema.json +35 -0
- package/entities/SuppressionsGlobalSuppressions/action.json +86 -0
- package/entities/SuppressionsGlobalSuppressions/schema.json +44 -0
- package/entities/SuppressionsSuppressions/action.json +127 -0
- package/entities/SuppressionsSuppressions/schema.json +35 -0
- package/entities/SuppressionsUnsubscribeGroups/action.json +106 -0
- package/entities/SuppressionsUnsubscribeGroups/schema.json +34 -0
- package/entities/Teammates/action.json +228 -0
- package/entities/Teammates/schema.json +40 -0
- package/entities/TransactionalTemplates/action.json +126 -0
- package/entities/TransactionalTemplates/schema.json +57 -0
- package/entities/TransactionalTemplatesVersions/action.json +105 -0
- package/entities/TransactionalTemplatesVersions/schema.json +45 -0
- package/entities/UsersAPI/action.json +189 -0
- package/entities/UsersAPI/schema.json +27 -0
- package/entities/Webhooks/action.json +148 -0
- package/entities/Webhooks/schema.json +58 -0
- package/error.json +190 -0
- package/metadata.json +77 -0
- package/package.json +81 -0
- package/pronghorn.json +17316 -0
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +1574 -0
- package/report/adapter-openapi.json +59750 -0
- package/report/adapter-openapi.yaml +43964 -0
- package/report/adapterInfo.json +10 -0
- package/report/auto-adapter-openapi.json +14137 -0
- package/report/creationReport.json +2750 -0
- package/report/sendgrid.json +48136 -0
- package/sampleProperties.json +257 -0
- package/test/integration/adapterTestBasicGet.js +83 -0
- package/test/integration/adapterTestConnectivity.js +118 -0
- package/test/integration/adapterTestIntegration.js +9099 -0
- package/test/unit/adapterBaseTestUnit.js +1024 -0
- package/test/unit/adapterTestUnit.js +8691 -0
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +74 -0
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +152 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +32 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +239 -0
- package/utils/tbUtils.js +489 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +193 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawnSync } = require('child_process');
|
|
6
|
+
const fs = require('fs-extra');
|
|
7
|
+
const { createBundle } = require('./artifactize');
|
|
8
|
+
|
|
9
|
+
const nodeEntryPath = path.resolve('.');
|
|
10
|
+
createBundle(nodeEntryPath).then((pathObj) => {
|
|
11
|
+
const { bundlePath, bundledAdapterPath } = pathObj;
|
|
12
|
+
const npmIgnorePath = path.join(bundledAdapterPath, '.npmignore');
|
|
13
|
+
const adapterPackagePath = path.join(bundledAdapterPath, 'package.json');
|
|
14
|
+
const artifactPackagePath = path.join(bundlePath, 'package.json');
|
|
15
|
+
|
|
16
|
+
// remove node_modules from .npmIgnore so that node_modules are included in the resulting tar from npm pack
|
|
17
|
+
let npmIgnoreString;
|
|
18
|
+
if (fs.existsSync(npmIgnorePath)) {
|
|
19
|
+
npmIgnoreString = fs.readFileSync(npmIgnorePath, 'utf8');
|
|
20
|
+
npmIgnoreString = npmIgnoreString.replace('node_modules', '');
|
|
21
|
+
npmIgnoreString = npmIgnoreString.replace('\n\n', '\n');
|
|
22
|
+
fs.writeFileSync(npmIgnorePath, npmIgnoreString);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// add files to package so that node_modules are included in the resulting tar from npm pack
|
|
26
|
+
const adapterPackage = fs.readJSONSync(adapterPackagePath);
|
|
27
|
+
adapterPackage.files = ['*'];
|
|
28
|
+
fs.writeJSONSync(artifactPackagePath, adapterPackage, { spaces: 2 });
|
|
29
|
+
const npmResult = spawnSync('npm', ['pack', '-q', bundlePath], { cwd: path.resolve(bundlePath, '..') });
|
|
30
|
+
if (npmResult.status === 0) {
|
|
31
|
+
fs.removeSync(bundlePath);
|
|
32
|
+
console.log('Bundle folder removed');
|
|
33
|
+
}
|
|
34
|
+
console.log('Script successful');
|
|
35
|
+
});
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# @copyright Itential, LLC 2019
|
|
3
|
+
|
|
4
|
+
#exit on any failure in the pipeline
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# --------------------------------------------------
|
|
8
|
+
# pre-commit
|
|
9
|
+
# --------------------------------------------------
|
|
10
|
+
# Contains the standard set of tasks to runbefore
|
|
11
|
+
# committing changes to the repo. If any tasks fail
|
|
12
|
+
# then the commit will be aborted.
|
|
13
|
+
# --------------------------------------------------
|
|
14
|
+
|
|
15
|
+
printf "%b" "Running pre-commit hooks...\\n"
|
|
16
|
+
|
|
17
|
+
# verify testing script is stubbed and no credentials
|
|
18
|
+
node utils/testRunner.js -r
|
|
19
|
+
|
|
20
|
+
# update the adapter information file
|
|
21
|
+
node utils/adapterInfo.js
|
|
22
|
+
node utils/methodDocumentor.js
|
|
23
|
+
git add CALLS.md report/adapterInfo.json
|
|
24
|
+
|
|
25
|
+
# security audit on the code
|
|
26
|
+
npm audit --registry=https://registry.npmjs.org --audit-level=moderate
|
|
27
|
+
|
|
28
|
+
# lint the code
|
|
29
|
+
npm run lint
|
|
30
|
+
|
|
31
|
+
# test the code
|
|
32
|
+
npm run test
|
|
@@ -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/setup.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This script will execute before an npm install command. The purpose is to
|
|
8
|
+
* write out some standard git hooks that will enable folks working on this
|
|
9
|
+
* project to benefit from the protections that the hooks provide.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const precommit = fs.readFileSync('utils/pre-commit.sh', 'utf8');
|
|
13
|
+
|
|
14
|
+
fs.stat('.git', (err) => {
|
|
15
|
+
if (err == null) {
|
|
16
|
+
// git repo, not an npm repo.
|
|
17
|
+
// add pre-commit hook if it doesn't exist
|
|
18
|
+
fs.stat('.git/hooks/pre-commit', (statErr) => {
|
|
19
|
+
if (statErr == null || statErr.code === 'ENOENT') {
|
|
20
|
+
fs.writeFile('.git/hooks/pre-commit', precommit, {
|
|
21
|
+
mode: 0o755
|
|
22
|
+
}, (writeErr) => {
|
|
23
|
+
if (writeErr) {
|
|
24
|
+
return console.log(writeErr.message);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
console.log(statErr.message);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const blacklistTasks = [
|
|
5
|
+
'genericAdapterRequest',
|
|
6
|
+
'genericAdapterRequestNoBasePath',
|
|
7
|
+
'hasEntities',
|
|
8
|
+
'healthcheck'
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const adapterBaseTasks = [
|
|
12
|
+
'getDevicesFiltered',
|
|
13
|
+
'isAlive',
|
|
14
|
+
'getConfig',
|
|
15
|
+
'getDevice',
|
|
16
|
+
'iapUpdateAdapterConfiguration',
|
|
17
|
+
'iapFindAdapterPath',
|
|
18
|
+
'iapSuspendAdapter',
|
|
19
|
+
'iapUnsuspendAdapter',
|
|
20
|
+
'iapGetAdapterQueue',
|
|
21
|
+
'iapTroubleshootAdapter',
|
|
22
|
+
'iapRunAdapterHealthcheck',
|
|
23
|
+
'iapRunAdapterConnectivity',
|
|
24
|
+
'iapRunAdapterBasicGet',
|
|
25
|
+
'iapMoveAdapterEntitiesToDB',
|
|
26
|
+
'getDevice',
|
|
27
|
+
'getDevicesFiltered',
|
|
28
|
+
'isAlive',
|
|
29
|
+
'getConfig',
|
|
30
|
+
'iapGetDeviceCount',
|
|
31
|
+
'iapRunAdapterLint',
|
|
32
|
+
'iapRunAdapterTests',
|
|
33
|
+
'iapGetAdapterInventory'
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
function updatePronghorn(tasks, original, updated) {
|
|
37
|
+
const originalFile = require(original);
|
|
38
|
+
const unusedMethods = [];
|
|
39
|
+
const usedMethods = originalFile.methods.filter((method) => {
|
|
40
|
+
if (tasks.includes(method.name)) {
|
|
41
|
+
unusedMethods.push(method);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
//write used and unused to new files
|
|
47
|
+
let updatedFile;
|
|
48
|
+
if (!fs.existsSync(updated)) {
|
|
49
|
+
updatedFile = { ...originalFile, methods: [], src: 'adapter-inactive.js' };
|
|
50
|
+
} else {
|
|
51
|
+
updatedFile = require(updated);
|
|
52
|
+
}
|
|
53
|
+
updatedFile.methods = updatedFile.methods.concat(unusedMethods);
|
|
54
|
+
originalFile.methods = usedMethods;
|
|
55
|
+
fs.writeFileSync(updated, JSON.stringify(updatedFile, null, 2));
|
|
56
|
+
fs.writeFileSync(original, JSON.stringify(originalFile, null, 2));
|
|
57
|
+
return 'Done';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function flipTaskFlag(task, pronghornPath, value)
|
|
61
|
+
{
|
|
62
|
+
const pronghorn = require(pronghornPath);
|
|
63
|
+
const index = pronghorn.methods.findIndex((method) => method.name === task);
|
|
64
|
+
pronghorn.methods[index] = { ...pronghorn.methods[index], task: value };
|
|
65
|
+
fs.writeFileSync(pronghornPath, JSON.stringify(pronghorn, null, 2));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//Return array of relevant paths given adapter directory
|
|
69
|
+
function createPaths(currentAdapter) {
|
|
70
|
+
const paths = [];
|
|
71
|
+
const filePaths = [
|
|
72
|
+
'adapter.js',
|
|
73
|
+
'pronghorn.json',
|
|
74
|
+
'test/integration/adapterTestIntegration.js',
|
|
75
|
+
'test/unit/adapterTestUnit.js',
|
|
76
|
+
'adapter-inactive.js',
|
|
77
|
+
'pronghorn-inactive.json',
|
|
78
|
+
];
|
|
79
|
+
filePaths.forEach((file) => {
|
|
80
|
+
paths.push(`${currentAdapter}/${file}`);
|
|
81
|
+
});
|
|
82
|
+
return paths;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function insert(str, index, value) {
|
|
86
|
+
return str.substr(0, index) + value + str.substr(index);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//modify adapter js
|
|
90
|
+
//original - path to file containing tasks we want to remove
|
|
91
|
+
// updated - path to file we want to move the tasks to
|
|
92
|
+
function updateAdapterJs(tasks, original, updated, adapterDir) {
|
|
93
|
+
if (!fs.existsSync(original)) {
|
|
94
|
+
//could do this or just let the error ocurr lower down and catch in warpper
|
|
95
|
+
throw new Error(`Original file ${original} does not exist.`);
|
|
96
|
+
}
|
|
97
|
+
let originalFile = fs.readFileSync(original, 'utf8');
|
|
98
|
+
let updatedFile;
|
|
99
|
+
if (!fs.existsSync(updated)) {
|
|
100
|
+
const adapterExport = require(`${adapterDir}/pronghorn.json`).export;
|
|
101
|
+
updatedFile = `/* @copyright Itential, LLC 2019 */\n\n/* eslint import/no-dynamic-require: warn */\n/* eslint no-unused-vars: warn */\n/* global log */\n\nconst path = require('path');\n\nconst AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));\n\nclass ${adapterExport}Inactive extends AdapterBaseCl {}\n`;
|
|
102
|
+
//To do handles backup files where og doesn't exist
|
|
103
|
+
} else {
|
|
104
|
+
updatedFile = fs.readFileSync(updated, 'utf8');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
tasks.forEach((method) => {
|
|
108
|
+
//accounting for different js docs format
|
|
109
|
+
const comment = originalFile.indexOf(`* @function ${method}`);
|
|
110
|
+
const start = originalFile.slice(0, comment).lastIndexOf('/**');
|
|
111
|
+
if (start !== -1) {
|
|
112
|
+
//next comment block
|
|
113
|
+
const end = originalFile.indexOf('/**\n', start + 1);
|
|
114
|
+
let func = end === -1
|
|
115
|
+
? originalFile.substring(start - 3, originalFile.lastIndexOf('}'))
|
|
116
|
+
: originalFile.substring(start, end);
|
|
117
|
+
originalFile = originalFile.replace(func, '');
|
|
118
|
+
func = '\n ' + func.trim() + '\n';
|
|
119
|
+
updatedFile = insert(updatedFile, updatedFile.lastIndexOf('}'), func);
|
|
120
|
+
} else {
|
|
121
|
+
console.log(`Task ${method} wasn't found in original file. Skipping.`);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
fs.writeFileSync(original, originalFile, 'utf8');
|
|
125
|
+
fs.writeFileSync(updated, updatedFile, 'utf8');
|
|
126
|
+
return 'done';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//Update test file for when we deactivate a task
|
|
130
|
+
function deactivateTest(adapterPath, testPath, tasks) {
|
|
131
|
+
let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
|
|
132
|
+
tasks.forEach((task) => {
|
|
133
|
+
const searchStr = `describe('#${task}`;
|
|
134
|
+
unitTest = unitTest.replace(searchStr, `describe.skip('#${task}`);
|
|
135
|
+
});
|
|
136
|
+
fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//Update test file when we activate tasks
|
|
140
|
+
function activateTest(adapterPath, testPath, tasks) {
|
|
141
|
+
let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
|
|
142
|
+
//tasks ==> toMove
|
|
143
|
+
tasks.forEach((task) => {
|
|
144
|
+
const searchStr = `describe.skip('#${task}`;
|
|
145
|
+
unitTest = unitTest.replace(searchStr, `describe('#${task}`);
|
|
146
|
+
});
|
|
147
|
+
fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//backups are not actually being written back
|
|
151
|
+
function rollbackChanges(adapterPath) {
|
|
152
|
+
const backups = fs.readdirSync(`${adapterPath}/temp`); //this is an array of file names not the full path
|
|
153
|
+
const filePaths = createPaths(adapterPath);
|
|
154
|
+
for (let i = 0; i < backups.length; i++) {
|
|
155
|
+
const file = fs.readFileSync(`${adapterPath}/temp/${backups[i]}`, 'utf8'); //make sure this is getting the file
|
|
156
|
+
const currentFile = filePaths.find((path) => {
|
|
157
|
+
const index = path.split('/').length - 1;
|
|
158
|
+
const fileName = path.split('/')[index];
|
|
159
|
+
return fileName === backups[i].replace('temp-', '');
|
|
160
|
+
}); //returns undefined if no match
|
|
161
|
+
|
|
162
|
+
if (currentFile) {
|
|
163
|
+
fs.writeFileSync(currentFile, file, 'utf8');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//inactive didn't exist before script
|
|
167
|
+
if (!backups.includes('temp-adapter-inactive.js')) {
|
|
168
|
+
fs.unlinkSync(`${adapterPath}/pronghorn-inactive.json`);
|
|
169
|
+
fs.unlinkSync(`${adapterPath}/adapter-inactive.js`);
|
|
170
|
+
}
|
|
171
|
+
deleteBackups(adapterPath);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function deleteBackups(adapterPath) {
|
|
175
|
+
fs.rmSync(`${adapterPath}/temp`, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function activateTasks(adapterDir, tasks) {
|
|
179
|
+
const toDelete = [];
|
|
180
|
+
const backupFiles = [];
|
|
181
|
+
const filePaths = createPaths(adapterDir);
|
|
182
|
+
try {
|
|
183
|
+
//take backup of each file here
|
|
184
|
+
if (!fs.existsSync(`${adapterDir}/temp`)) {
|
|
185
|
+
fs.mkdirSync(`${adapterDir}/temp`);
|
|
186
|
+
}
|
|
187
|
+
filePaths.forEach((filePath) => {
|
|
188
|
+
if (fs.existsSync(filePath)) {
|
|
189
|
+
const index = filePath.split('/').length - 1;
|
|
190
|
+
const backupName = `temp-${filePath.split('/')[index]}`;
|
|
191
|
+
backupFiles.push(`${adapterDir}/temp/${backupName}`);
|
|
192
|
+
fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
|
|
193
|
+
} else {
|
|
194
|
+
//File doesn't exist before script
|
|
195
|
+
toDelete.push(filePath);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
tasks = tasks.filter((task) => {
|
|
199
|
+
if (adapterBaseTasks.includes(task)) {
|
|
200
|
+
flipTaskFlag(task, `${adapterDir}/pronghorn.json`, true);
|
|
201
|
+
return false;
|
|
202
|
+
} else {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
updateAdapterJs(
|
|
207
|
+
tasks,
|
|
208
|
+
`${adapterDir}/adapter-inactive.js`,
|
|
209
|
+
`${adapterDir}/adapter.js`,
|
|
210
|
+
adapterDir
|
|
211
|
+
);
|
|
212
|
+
updatePronghorn(
|
|
213
|
+
tasks,
|
|
214
|
+
`${adapterDir}/pronghorn-inactive.json`,
|
|
215
|
+
`${adapterDir}/pronghorn.json`
|
|
216
|
+
);
|
|
217
|
+
activateTest(
|
|
218
|
+
adapterDir,
|
|
219
|
+
'/test/integration/adapterTestIntegration.js',
|
|
220
|
+
tasks
|
|
221
|
+
);
|
|
222
|
+
activateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
|
|
223
|
+
return 'success';
|
|
224
|
+
} catch (e) {
|
|
225
|
+
console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
|
|
226
|
+
for (let i = 0; i < backupFiles.length; i++) {
|
|
227
|
+
const file = fs.readFileSync(backupFiles[i], 'utf8');
|
|
228
|
+
fs.writeFileSync(filePaths[i], file, 'utf8');
|
|
229
|
+
}
|
|
230
|
+
toDelete.forEach((filePath) => {
|
|
231
|
+
if (fs.existsSync(filePath)) {
|
|
232
|
+
fs.unlinkSync(filePath);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
deleteBackups(adapterDir);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//moving from adapter.js to adapter-inactive.js
|
|
241
|
+
function deactivateTasks(adapterDir, tasks) {
|
|
242
|
+
const toDelete = [];
|
|
243
|
+
const backupFiles = [];
|
|
244
|
+
const filePaths = createPaths(adapterDir);
|
|
245
|
+
try {
|
|
246
|
+
//take backup of each file here
|
|
247
|
+
if (!fs.existsSync(`${adapterDir}/temp`)) {
|
|
248
|
+
fs.mkdirSync(`${adapterDir}/temp`);
|
|
249
|
+
}
|
|
250
|
+
filePaths.forEach((filePath) => {
|
|
251
|
+
if (fs.existsSync(filePath)) {
|
|
252
|
+
const index = filePath.split('/').length - 1;
|
|
253
|
+
const backupName = `temp-${filePath.split('/')[index]}`;
|
|
254
|
+
backupFiles.push(`${adapterDir}/temp/${backupName}`);
|
|
255
|
+
fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
|
|
256
|
+
} else {
|
|
257
|
+
//File doesn't exist before script
|
|
258
|
+
toDelete.push(filePath);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
//filter tasks for blacklisted tasks or IAP tasks
|
|
262
|
+
tasks = tasks.filter((task) => {
|
|
263
|
+
if (blacklistTasks.includes(task)) {
|
|
264
|
+
console.log(`${task} cannot be deactivated.`);
|
|
265
|
+
return false;
|
|
266
|
+
} else if (adapterBaseTasks.includes(task)) {
|
|
267
|
+
flipTaskFlag(task, `${adapterDir}/pronghorn.json`, false);
|
|
268
|
+
return false;
|
|
269
|
+
} else {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
updateAdapterJs(
|
|
274
|
+
tasks,
|
|
275
|
+
`${adapterDir}/adapter.js`,
|
|
276
|
+
`${adapterDir}/adapter-inactive.js`,
|
|
277
|
+
adapterDir
|
|
278
|
+
);
|
|
279
|
+
updatePronghorn(
|
|
280
|
+
tasks,
|
|
281
|
+
`${adapterDir}/pronghorn.json`,
|
|
282
|
+
`${adapterDir}/pronghorn-inactive.json`
|
|
283
|
+
);
|
|
284
|
+
deactivateTest(
|
|
285
|
+
adapterDir,
|
|
286
|
+
'/test/integration/adapterTestIntegration.js',
|
|
287
|
+
tasks
|
|
288
|
+
);
|
|
289
|
+
deactivateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
|
|
290
|
+
return 'success';
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
|
|
293
|
+
for (let i = 0; i < backupFiles.length; i++) {
|
|
294
|
+
const file = fs.readFileSync(backupFiles[i], 'utf8');
|
|
295
|
+
fs.writeFileSync(filePaths[i], file, 'utf8');
|
|
296
|
+
}
|
|
297
|
+
toDelete.forEach((filePath) => {
|
|
298
|
+
if (fs.existsSync(filePath)) {
|
|
299
|
+
fs.unlinkSync(filePath);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
deleteBackups(adapterDir);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = {
|
|
308
|
+
activateTasks, deactivateTasks, rollbackChanges, deleteBackups
|
|
309
|
+
};
|