@mablhq/mabl-cli 2.50.12 → 2.51.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/cli.js CHANGED
@@ -43,6 +43,7 @@ yargs
43
43
  .commandDir('./commands/branches')
44
44
  .commandDir('./commands/config')
45
45
  .commandDir('./commands/credentials')
46
+ .commandDir('./commands/databases')
46
47
  .commandDir('./commands/datatables')
47
48
  .commandDir('./commands/deploy')
48
49
  .commandDir('./commands/environments')
@@ -10,12 +10,12 @@ const chalk_1 = __importDefault(require("chalk"));
10
10
  const loggingProvider_1 = require("../../../../providers/logging/loggingProvider");
11
11
  const mablApi_1 = require("../../../../mablApi");
12
12
  const mablApiClientFactory_1 = require("../../../../api/mablApiClientFactory");
13
- exports.command = `add ${constants_1.CommandArgId}`;
14
- exports.describe = 'Associate urls with an environment';
13
+ exports.command = `add <${constants_1.CommandArgId}>`;
14
+ exports.describe = 'Associate URLs with an environment';
15
15
  exports.builder = (yargs) => {
16
16
  addEnvironmentUrlOptions(yargs)
17
17
  .positional(constants_1.CommandArgId, {
18
- describe: 'Id of environment to add url associations to',
18
+ describe: 'Id of environment to add URL associations to',
19
19
  type: 'string',
20
20
  })
21
21
  .demandOption(constants_1.CommandArgApplicationId);
@@ -29,11 +29,11 @@ function addEnvironmentUrlOptions(yargs) {
29
29
  type: 'string',
30
30
  })
31
31
  .option(constants_1.CommandArgUrlApp, {
32
- describe: 'web application urls to associate with the application-environment pair',
32
+ describe: 'web application URLs to associate with the application-environment pair',
33
33
  type: 'array',
34
34
  })
35
35
  .option(constants_1.CommandArgUrlApi, {
36
- describe: 'api urls to associate with the application-environment pair',
36
+ describe: 'API URLs to associate with the application-environment pair',
37
37
  type: 'array',
38
38
  })
39
39
  .check((argv) => {
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PRE_REQUEST_LISTEN = exports.convertMablAssertionsToExecArray = exports.convertMablVariableAssignmentsToExecArray = exports.createMablGeneratedScripts = exports.insertMablAssertionScripts = exports.toPostmanScript = exports.replaceVariables = exports.getActualValue = exports.readBody = exports.getResponseContentType = exports.valueToUnquotedString = exports.assertionTypeSupportsCaseSensitivity = exports.assertionTargetSupportsCaseSensitivity = exports.humanizeAssertion = exports.getAssertionTargetArgument = exports.assertionHasTest = exports.isValidMablAssertion = exports.normalizeRegExpExpectedValue = exports.normalizeExpectedValue = exports.normalizeAssertionValue = exports.assertionRequiresValue = exports.filterValidMablAssertions = exports.filterValidMablVariableAssignments = exports.isValidMablVariableAssignment = exports.removeMablGeneratedScripts = exports.createEmptyRequestEvent = exports.findFirstMatchingEvent = exports.restoreCustomRequestFields = exports.deduplicateApiTestExecutionResults = exports.createEmptyVariable = exports.createEmptyAssertion = exports.humanizeAssertionType = exports.getAssertionTypesForTarget = exports.caseInsensitiveEquals = exports.compareStringsCaseInsensitive = exports.ASSERT_TYPES = exports.ASSERT_TARGETS = exports.COLLECTION_WITH_FOLDERS_ERROR = exports.HMAC_SHA1_SIGNATURE = exports.DEFAULT_ADD_OAUTH1_TO_HEADER_VALUE = exports.DEFAULT_OAUTH1_VERSION = exports.OAUTH1_AUTH = exports.NO_AUTH = exports.BEARER_TOKEN_AUTH = exports.BASIC_AUTH = exports.API_KEY_AUTH = exports.INHERIT_AUTH_FROM_PARENT_VALUE = exports.MABL_GENERATED_COMMENT = exports.MABL_GENERATED_ASSERTION_TOKEN = exports.TEST_LISTEN = void 0;
7
- exports.uuid = exports.createCommentForApiTestSnippet = exports.convertMablSnippetsToExecArray = exports.createPostmanScript = exports.insertMablScriptsIntoCollection = exports.processPostmanItem = exports.replaceRawScriptWithExecArray = exports.removeInvalidHeaders = exports.processItemAuth = exports.mablAuthToPostman = exports.formatContent = exports.getRequestMode = exports.getFormDataArray = exports.isText = exports.isXML = exports.isJson = exports.isSupportedAuthType = exports.isItemDefinition = exports.isCollectionDefinition = exports.isItemGroupDefinition = exports.isFolder = exports.validateCollectionFeaturesForApiTestEditor = exports.generateRawScriptField = exports.processPostmanItems = exports.createEmptyRequest = exports.createEmptyRequestEventArray = exports.splitLines = void 0;
7
+ exports.uuid = exports.insertTestConfigurationIntoFlow = exports.createCommentForApiTestSnippet = exports.convertMablSnippetsToExecArray = exports.createPostmanScript = exports.insertMablScriptsIntoCollection = exports.processPostmanItem = exports.replaceRawScriptWithExecArray = exports.removeInvalidHeaders = exports.processItemAuth = exports.mablAuthToPostman = exports.formatContent = exports.getRequestMode = exports.getFormDataArray = exports.isText = exports.isXML = exports.isJson = exports.isSupportedAuthType = exports.isItemDefinition = exports.isCollectionDefinition = exports.isItemGroupDefinition = exports.isFolder = exports.validateCollectionFeaturesForApiTestEditor = exports.generateRawScriptField = exports.processPostmanItems = exports.createEmptyRequest = exports.createEmptyRequestEventArray = exports.splitLines = void 0;
8
8
  const newman_types_1 = require("./newman-types");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
10
  const uuid_1 = require("uuid");
@@ -997,13 +997,10 @@ function processPostmanItem(item) {
997
997
  removeInvalidHeaders(item);
998
998
  }
999
999
  exports.processPostmanItem = processPostmanItem;
1000
- function insertMablScriptsIntoCollection(collection, getSnippet) {
1000
+ function insertMablScriptsIntoCollection(itemGroup, getSnippet) {
1001
1001
  var _a, _b;
1002
- (_a = collection.event) === null || _a === void 0 ? void 0 : _a.forEach((event) => insertMablScriptsIntoEvent(event, getSnippet));
1003
- (_b = collection.item) === null || _b === void 0 ? void 0 : _b.forEach((item) => {
1004
- var _a;
1005
- return (_a = item.event) === null || _a === void 0 ? void 0 : _a.forEach((event) => insertMablScriptsIntoEvent(event, getSnippet));
1006
- });
1002
+ (_a = itemGroup.event) === null || _a === void 0 ? void 0 : _a.forEach((event) => insertMablScriptsIntoEvent(event, getSnippet));
1003
+ (_b = itemGroup.item) === null || _b === void 0 ? void 0 : _b.forEach((item) => insertMablScriptsIntoCollection(item, getSnippet));
1007
1004
  }
1008
1005
  exports.insertMablScriptsIntoCollection = insertMablScriptsIntoCollection;
1009
1006
  function insertMablScriptsIntoEvent(event, getSnippet) {
@@ -1060,5 +1057,140 @@ function createCommentForApiTestSnippet(snippet, position) {
1060
1057
  return `// ${position} of one-time snippet "${(_b = snippet.name) !== null && _b !== void 0 ? _b : snippet.id}"`;
1061
1058
  }
1062
1059
  exports.createCommentForApiTestSnippet = createCommentForApiTestSnippet;
1060
+ function insertTestConfigurationIntoFlow(test, flow) {
1061
+ var _a;
1062
+ const collection = flow.api_steps;
1063
+ const testConfiguration = test.api_configuration;
1064
+ if (!testConfiguration) {
1065
+ return;
1066
+ }
1067
+ const { authentication, pre_request_snippets: preRequestSnippets, post_request_snippets: postRequestSnippets, } = testConfiguration;
1068
+ if (!authentication &&
1069
+ !(preRequestSnippets === null || preRequestSnippets === void 0 ? void 0 : preRequestSnippets.length) &&
1070
+ !(postRequestSnippets === null || postRequestSnippets === void 0 ? void 0 : postRequestSnippets.length)) {
1071
+ return;
1072
+ }
1073
+ const folder = {
1074
+ name: (_a = flow.id) !== null && _a !== void 0 ? _a : 'Flow',
1075
+ item: collection.item,
1076
+ };
1077
+ folder.auth = collection.auth;
1078
+ folder.event = collection.event;
1079
+ delete collection.auth;
1080
+ delete collection.event;
1081
+ collection.item = [folder];
1082
+ if (authentication) {
1083
+ collection.auth = apiTestAuthToPostmanAuth(authentication);
1084
+ }
1085
+ const event = [];
1086
+ if (preRequestSnippets === null || preRequestSnippets === void 0 ? void 0 : preRequestSnippets.length) {
1087
+ event.push(executableSnippetsToPostmanEvent(preRequestSnippets, 'prerequest'));
1088
+ }
1089
+ if (postRequestSnippets === null || postRequestSnippets === void 0 ? void 0 : postRequestSnippets.length) {
1090
+ event.push(executableSnippetsToPostmanEvent(postRequestSnippets, 'test'));
1091
+ }
1092
+ if (event.length) {
1093
+ collection.event = event;
1094
+ }
1095
+ }
1096
+ exports.insertTestConfigurationIntoFlow = insertTestConfigurationIntoFlow;
1097
+ function apiTestAuthToPostmanAuth(apiTestAuth) {
1098
+ const postmanAuth = {
1099
+ type: `${apiTestAuth.type}`,
1100
+ };
1101
+ switch (apiTestAuth.type) {
1102
+ case 'apikey':
1103
+ postmanAuth.apikey = apiKeyAuthenticationToPostman(apiTestAuth.api_key);
1104
+ break;
1105
+ case 'basic':
1106
+ postmanAuth.basic = basicAuthenticationToPostman(apiTestAuth.basic);
1107
+ break;
1108
+ case 'bearer':
1109
+ postmanAuth.bearer = bearerAuthenticationToPostman(apiTestAuth.bearer);
1110
+ break;
1111
+ case 'oauth1':
1112
+ postmanAuth.oauth1 = oauth1AuthenticationToPostman(apiTestAuth.oauth1);
1113
+ break;
1114
+ }
1115
+ return postmanAuth;
1116
+ }
1117
+ function apiKeyAuthenticationToPostman(auth) {
1118
+ return removeUndefinedValues([
1119
+ toPostmanConfigurationValue('key', auth === null || auth === void 0 ? void 0 : auth.key),
1120
+ toPostmanConfigurationValue('value', auth === null || auth === void 0 ? void 0 : auth.value),
1121
+ toPostmanConfigurationValue('in', auth === null || auth === void 0 ? void 0 : auth.location),
1122
+ ]);
1123
+ }
1124
+ function basicAuthenticationToPostman(auth) {
1125
+ return removeUndefinedValues([
1126
+ toPostmanConfigurationValue('username', auth === null || auth === void 0 ? void 0 : auth.username),
1127
+ toPostmanConfigurationValue('password', auth === null || auth === void 0 ? void 0 : auth.password),
1128
+ ]);
1129
+ }
1130
+ function bearerAuthenticationToPostman(auth) {
1131
+ return removeUndefinedValues([
1132
+ toPostmanConfigurationValue('token', auth === null || auth === void 0 ? void 0 : auth.token),
1133
+ ]);
1134
+ }
1135
+ function oauth1AuthenticationToPostman(auth) {
1136
+ return removeUndefinedValues([
1137
+ toPostmanConfigurationValue('addParamsToHeader', auth === null || auth === void 0 ? void 0 : auth.add_parameters_to_header, 'boolean'),
1138
+ toPostmanConfigurationValue('addEmptyParamsToSign', auth === null || auth === void 0 ? void 0 : auth.add_empty_parameters_to_signature, 'boolean'),
1139
+ toPostmanConfigurationValue('callback', auth === null || auth === void 0 ? void 0 : auth.callback_url),
1140
+ toPostmanConfigurationValue('consumerKey', auth === null || auth === void 0 ? void 0 : auth.consumer_key),
1141
+ toPostmanConfigurationValue('consumerSecret', auth === null || auth === void 0 ? void 0 : auth.consumer_secret),
1142
+ toPostmanConfigurationValue('includeBodyHash', auth === null || auth === void 0 ? void 0 : auth.include_body_hash, 'boolean'),
1143
+ toPostmanConfigurationValue('nonce', auth === null || auth === void 0 ? void 0 : auth.nonce),
1144
+ toPostmanConfigurationValue('realm', auth === null || auth === void 0 ? void 0 : auth.realm),
1145
+ toPostmanConfigurationValue('signatureMethod', auth === null || auth === void 0 ? void 0 : auth.signature_method),
1146
+ toPostmanConfigurationValue('timestamp', auth === null || auth === void 0 ? void 0 : auth.timestamp),
1147
+ toPostmanConfigurationValue('token', auth === null || auth === void 0 ? void 0 : auth.token),
1148
+ toPostmanConfigurationValue('tokenSecret', auth === null || auth === void 0 ? void 0 : auth.token_secret),
1149
+ toPostmanConfigurationValue('verifier', auth === null || auth === void 0 ? void 0 : auth.verifier),
1150
+ toPostmanConfigurationValue('version', auth === null || auth === void 0 ? void 0 : auth.version),
1151
+ ]);
1152
+ }
1153
+ const removeUndefinedValues = (values) => values.filter((value) => value !== undefined);
1154
+ function toPostmanConfigurationValue(key, value, type = 'string') {
1155
+ if (!value) {
1156
+ return;
1157
+ }
1158
+ if (type === 'string') {
1159
+ value = `${value}`;
1160
+ }
1161
+ if (type === 'boolean') {
1162
+ value = `${value}`.toLowerCase() === 'true';
1163
+ }
1164
+ return {
1165
+ key,
1166
+ value,
1167
+ type,
1168
+ };
1169
+ }
1170
+ function executableSnippetsToPostmanEvent(snippets, type) {
1171
+ return {
1172
+ id: (0, exports.uuid)(),
1173
+ listen: type,
1174
+ mablSnippets: snippets.map((snippet) => executableSnippetToApiTestSnippet(snippet)),
1175
+ script: {
1176
+ exec: [],
1177
+ id: (0, exports.uuid)(),
1178
+ type: 'text/javascript',
1179
+ },
1180
+ };
1181
+ }
1182
+ function executableSnippetToApiTestSnippet(executableSnippet) {
1183
+ const { invariant_id: invariantId, ...snippet } = { ...executableSnippet };
1184
+ if (executableSnippet.reusable) {
1185
+ return {
1186
+ invariantId: invariantId,
1187
+ reusable: true,
1188
+ };
1189
+ }
1190
+ return {
1191
+ ...snippet,
1192
+ reusable: false,
1193
+ };
1194
+ }
1063
1195
  const uuid = () => (0, uuid_1.v4)();
1064
1196
  exports.uuid = uuid;