Skip to content

Commit

Permalink
Prep for Release: source maps, types, prettier (#301)
Browse files Browse the repository at this point in the history
* updates library exports

* fixes lint configuration

so that it actually fails now, as intended

* tidy up

---------

Co-authored-by: Filipe Freire <[email protected]>
  • Loading branch information
dimitropoulos and filfreire authored Jul 12, 2024
1 parent fbd23b5 commit 6a758d6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 27 deletions.
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "Kong <[email protected]>",
"homepage": "https://github.com/Kong/httpsnippet",
"license": "MIT",
"main": "dist/httpsnippet.js",
"types": "dist/httpsnippet.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": "bin/httpsnippet",
"keywords": [
"api",
Expand Down Expand Up @@ -51,9 +51,13 @@
"clean": "tsc --build tsconfig.build.json --clean",
"prebuild": "npm run clean",
"lint": "npm run lint:prettify && npm run lint:code && npm run lint:markdown",
"lint:prettify": "prettier --write .",
"lint:code": "eslint . --ext ts,d.ts,test.ts --fix",
"lint:prettify": "prettier --check .",
"lint:code": "eslint . --ext ts,d.ts,test.ts",
"lint:markdown": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\"",
"lint:fix": "npm run lint:prettify:fix && npm run lint:code:fix && npm run lint:markdown:fix",
"lint:prettify:fix": "prettier --write .",
"lint:code:fix": "eslint . --ext ts,d.ts,test.ts --fix",
"lint:markdown:fix": "markdownlint-cli2-fix \"**/*.md\" \"#**/node_modules\"",
"build": "tsc --build tsconfig.build.json",
"build:types": "tsc -d --declarationDir dist/lib --declarationMap --emitDeclarationOnly",
"test": "jest"
Expand Down
4 changes: 2 additions & 2 deletions src/httpsnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface Entry {
request: Partial<HarRequest>;
}

interface HarEntry {
export interface HarEntry {
log: {
version: string;
creator: {
Expand All @@ -64,7 +64,7 @@ interface HarEntry {
};
}

const isHarEntry = (value: any): value is HarEntry =>
export const isHarEntry = (value: any): value is HarEntry =>
typeof value === 'object' &&
'log' in value &&
typeof value.log === 'object' &&
Expand Down
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export { CodeBuilder, CodeBuilderOptions, PostProcessor } from './helpers/code-builder';
export { EscapeOptions, escapeString } from './helpers/escape';
export { HARError, validateHarRequest } from './helpers/har-validator';
export { getHeader, getHeaderName } from './helpers/headers';
export { AvailableTarget, availableTargets, extname } from './helpers/utils';
export {
HarEntry,
HarRequest,
HTTPSnippet,
isHarEntry,
Request,
RequestExtras,
} from './httpsnippet';
export {
addTarget,
addTargetClient,
Client,
ClientId,
ClientInfo,
Converter,
Extension,
isClient,
isTarget,
Target,
TargetId,
TargetInfo,
targets,
} from './targets/targets';
6 changes: 4 additions & 2 deletions src/targets/powershell/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
'PATCH',
'POST',
'PUT',
'TRACE'
'TRACE',
];
const methodArg = methods.includes(method.toUpperCase()) ? '-Method' : '-CustomMethod';

Expand Down Expand Up @@ -73,7 +73,9 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
commandOptions.push(`-Body '${postData.text}'`);
}

push(`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`);
push(
`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`,
);
return join();
};
return convert;
Expand Down
24 changes: 14 additions & 10 deletions src/targets/ruby/faraday/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const faraday: Client = {
link: 'https://github.com/lostisland/faraday',
description: 'Faraday HTTP client',
},
convert: ({ uriObj, queryObj, method: rawMethod, fullUrl, postData, allHeaders }, options = {}) => {
convert: ({ uriObj, queryObj, method: rawMethod, postData, allHeaders }) => {
const { push, blank, join } = new CodeBuilder();

// To support custom methods we check for the supported methods
Expand All @@ -30,16 +30,16 @@ export const faraday: Client = {
'TRACE',
];

if(!methods.includes(method)) {
push(`# Faraday cannot currently run ${method} requests. Please use another client.`)
if (!methods.includes(method)) {
push(`# Faraday cannot currently run ${method} requests. Please use another client.`);
return join();
}

push("require 'faraday'");
blank();

// Write body to beginning of script
if(postData.mimeType === 'application/x-www-form-urlencoded') {
if (postData.mimeType === 'application/x-www-form-urlencoded') {
if (postData.params) {
push(`data = {`);
postData.params.forEach(param => {
Expand All @@ -52,8 +52,12 @@ export const faraday: Client = {

push(`conn = Faraday.new(`);
push(` url: '${uriObj.protocol}//${uriObj.host}',`);
if(allHeaders['content-type'] || allHeaders['Content-Type']) {
push(` headers: {'Content-Type' => '${allHeaders['content-type'] || allHeaders['Content-Type']}'}`);
if (allHeaders['content-type'] || allHeaders['Content-Type']) {
push(
` headers: {'Content-Type' => '${
allHeaders['content-type'] || allHeaders['Content-Type']
}'}`,
);
}
push(`)`);

Expand All @@ -63,7 +67,7 @@ export const faraday: Client = {
const headers = Object.keys(allHeaders);
if (headers.length) {
headers.forEach(key => {
if(key.toLowerCase() !== 'content-type') {
if (key.toLowerCase() !== 'content-type') {
push(` req.headers['${key}'] = '${escapeForSingleQuotes(allHeaders[key])}'`);
}
});
Expand All @@ -72,9 +76,9 @@ export const faraday: Client = {
Object.keys(queryObj).forEach(name => {
const value = queryObj[name];
if (Array.isArray(value)) {
push(` req.params['${name}'] = ${JSON.stringify(value)}`)
push(` req.params['${name}'] = ${JSON.stringify(value)}`);
} else {
push(` req.params['${name}'] = '${value}'`)
push(` req.params['${name}'] = '${value}'`);
}
});

Expand All @@ -98,7 +102,7 @@ export const faraday: Client = {
}

push('end');
blank()
blank();
push('puts response.status');
push('puts response.body');

Expand Down
4 changes: 2 additions & 2 deletions src/targets/ruby/target.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Target } from '../targets';
import { native } from './native/client';
import { faraday } from './faraday/client';
import { native } from './native/client';

export const ruby: Target = {
info: {
Expand All @@ -11,6 +11,6 @@ export const ruby: Target = {
},
clientsById: {
native,
faraday
faraday,
},
};
15 changes: 8 additions & 7 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"allowJs": true,
"resolveJsonModule": true,
"strict": true,
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"downlevelIteration": true,
"lib": ["ESNext"],
"declaration": true,
"declarationMap": true
"esModuleInterop": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": "src",
"sourceMap": true,
"strict": true
},
"include": ["src"],
"exclude": ["dist", "**/*.test.ts"]
Expand Down

0 comments on commit 6a758d6

Please sign in to comment.