Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint tests passed
  • Loading branch information
admin committed Jan 21, 2021
commit 2a1c7253494c246e50ba5b5c812e448eb2b6d451
44 changes: 18 additions & 26 deletions codegens/js-urlfetchapp/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ var _ = require('./lodash'),
addFormParam = require('./util').addFormParam,
path = require('path');

// var _ = require(['./lodash']),
// sanitize = require(['./util']).sanitize,
// sanitizeOptions = require(['./util']).sanitizeOptions,
// addFormParam = require(['./util']).addFormParam,
// path = require(['path']);

/**
* Parses URLEncoded body from request
*
Expand Down Expand Up @@ -93,14 +87,14 @@ function parseFormData (body, trim) {
if (data.type === 'file') {
var pathArray = data.src.split(path.sep),
fileName = pathArray[pathArray.length - 1];
bodySnippet += `${indent}"${sanitize(data.key, trim)}": DriveApp.getFileById(${fileName}).getBlob(),\n `;
bodySnippet += ` "${sanitize(data.key, trim)}": DriveApp.getFileById(${fileName}).getBlob(),\n `;
}
else {
bodySnippet += `${indent}"${sanitize(data.key, trim)}": "${sanitize(data.value, trim)}",\n`;
bodySnippet += ` "${sanitize(data.key, trim)}": "${sanitize(data.value, trim)}",\n`;
}
}
});
bodySnippet += '};'
bodySnippet += '};';
return bodySnippet;
}

Expand Down Expand Up @@ -156,10 +150,10 @@ function parseHeaders (headers) {
if (!_.isEmpty(headers)) {
headers = _.reject(headers, 'disabled');
_.forEach(headers, function (header) {
headerSnippet += `${indent}"${sanitize(header.key, true)}": "${sanitize(header.value)}",\n`;
headerSnippet += ` "${sanitize(header.key, true)}": "${sanitize(header.value)}",\n`;
});
}
headerSnippet += `};\n`;
headerSnippet += '};\n';
return headerSnippet;
}

Expand Down Expand Up @@ -278,35 +272,33 @@ function convert (request, options, callback) {
// codeSnippet += `${indent}if(this.readyState === 4) {\n`;
// codeSnippet += `${indent.repeat(2)}console.log(this.responseText);\n`;
// codeSnippet += `${indent}}\n});\n\n`;

// codeSnippet += 'var xhr = new XMLHttpRequest();\nxhr.withCredentials = true;\n\n';





if (options.requestTimeout) {
// requestTimeout not supported
// See https://issuetracker.google.com/issues/36761852 for more information
codeSnippet += `//requestTimeout not supported\n\n`;
codeSnippet += `// See https://issuetracker.google.com/issues/36761852 for more information \n\n`;
// See https://issuetracker.google.com/issues/36761852 for more information
codeSnippet += '//requestTimeout not supported\n\n';
codeSnippet += '// See https://issuetracker.google.com/issues/36761852 for more information \n\n';
}

headerSnippet = parseHeaders(request.toJSON().header);

codeSnippet += headerSnippet + '\n';
codeSnippet += `var options = {\n`;

codeSnippet += 'var options = {\n';
codeSnippet += `${indent}'method' : ${request.method},\n`;
codeSnippet += `${indent}'payload' : formData,\n`;
codeSnippet += `${indent}'header' : header,\n`;
codeSnippet += `};\n`;
codeSnippet += `\n`;
codeSnippet += '};\n';
codeSnippet += '\n';

if (request.body && request.body.mode === 'graphql' && !request.headers.has('Content-Type')) {
codeSnippet += `UrlFetchApp.fetch(encodeURI(${encodeURI(request.url.toString())}), options);\n`;
}
}
else {
codeSnippet += `UrlFetchApp.fetch('${encodeURI(request.url.toString())}', options);\n`;
codeSnippet += `UrlFetchApp.fetch('${encodeURI(request.url.toString())}', options);\n`;
}
callback(null, codeSnippet);
}
Expand Down
9 changes: 0 additions & 9 deletions codegens/js-urlfetchapp/lib/index_bp.js

This file was deleted.

2 changes: 0 additions & 2 deletions codegens/js-urlfetchapp/npm/test-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ var shell = require('shelljs'),
*/
LINT_SOURCE_DIRS = [
'./lib',
'./bin',
'./test',
'./examples/*.js',
'./npm/*.js',
'./index.js'
];
Expand Down
2 changes: 1 addition & 1 deletion codegens/js-urlfetchapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"type": "git",
"url": ""
},
"author": "Ray Liu <[email protected]>",
"author": "Postman Labs <[email protected]>",
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators/tree/master/codegens/js-urlfetchapp",
"dependencies": {},
Expand Down
12 changes: 12 additions & 0 deletions dummyBinaryFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
\x123\x344\x233\xAdd
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,31 @@
"async": "2.6.3",
"path": "0.12.7",
"postman-collection": "3.6.8",
"shelljs": "0.8.4"
"shelljs": "0.8.4",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"browserify": "14.5.0",
"chai": "4.2.0",
"chalk": "2.4.2",
"eslint": "5.16.0",
"dependency-check": "2.10.1",
"editorconfig": "0.15.3",
"eslint": "5.16.0",
"eslint-plugin-jsdoc": "3.15.1",
"eslint-plugin-lodash": "2.7.0",
"eslint-plugin-mocha": "4.12.1",
"eslint-plugin-security": "1.4.0",
"istanbul": "0.4.5",
"js-yaml": "3.14.0",
"newman": "5.2.0",
"jsdoc": "3.6.6",
"mocha": "5.2.0",
"lodash": "4.17.20",
"mocha": "5.2.0",
"newman": "5.2.0",
"nyc": "14.1.1",
"parse-gitignore": "1.0.1",
"pretty-ms": "3.2.0",
"recursive-readdir": "2.2.2",
"typescript": "^4.1.3",
"watchify": "3.11.1"
},
"engines": {
Expand Down
73 changes: 38 additions & 35 deletions test/codegen/newman/fixtures/formdataFileCollection.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
{
"info": {
"_postman_id": "7da8f1cd-aeb0-420f-a989-d47db46b44b0",
"name": "Multipart/form-data FILE",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Single/multiple file upload via form-data",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"info": {
"_postman_id": "7da8f1cd-aeb0-420f-a989-d47db46b44b0",
"name": "Multipart/form-data FILE",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Single/multiple file upload via form-data",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "single file",
"value": "",
"type": "file",
"src": "<file path>"
},
{
"src": "/home/admin/postman-code-generators/dummyFile1.txt"
},
{
"key": "multiple files",
"value": "",
"type": "file",
"src": ["<file path 1>","<file path 2>"]
"src": [
"/home/admin/postman-code-generators/dummyFile2.txt",
"/home/admin/postman-code-generators/dummyFile3.txt"
]
}
]
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
}
]
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
}
},
{
"name": "Binary file upload via form-data",
Expand All @@ -52,7 +55,7 @@
"key": "binary file",
"value": "",
"type": "file",
"src": "<file path>"
"src": "/home/admin/postman-code-generators/dummyBinaryFile"
}
]
},
Expand All @@ -69,5 +72,5 @@
}
}
}
]
]
}