@readme/httpsnippet 4.1.0 → 5.0.0

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/README.md CHANGED
@@ -157,6 +157,7 @@ There are some major differences between this library and the [httpsnippet](http
157
157
 
158
158
  * Includes a full integration test suite for a handful of clients and targets.
159
159
  * Does not ship with a CLI component.
160
+ * Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid.
160
161
  * The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
161
162
  * We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data.
162
163
  * Node
@@ -1,4 +1,4 @@
1
- export declare type PostProcessor = (unreplacedCode: string) => string;
1
+ export type PostProcessor = (unreplacedCode: string) => string;
2
2
  export interface CodeBuilderOptions {
3
3
  /**
4
4
  * Desired indentation character for aggregated lines of code
@@ -32,7 +32,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
32
32
  function verb(n) { return function (v) { return step([n, v]); }; }
33
33
  function step(op) {
34
34
  if (f) throw new TypeError("Generator is already executing.");
35
- while (_) try {
35
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
36
36
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
37
37
  if (y = 0, t) op = [op[0] & 2, t.value];
38
38
  switch (op[0]) {
@@ -1,4 +1,4 @@
1
- declare type Headers<T> = Record<string, T>;
1
+ type Headers<T> = Record<string, T>;
2
2
  /**
3
3
  * Given a headers object retrieve a specific header out of it via a case-insensitive key.
4
4
  */
@@ -1,4 +1,4 @@
1
- export declare type ReducedHelperObject = Record<string, string[] | string>;
1
+ export type ReducedHelperObject = Record<string, string[] | string>;
2
2
  export declare const reducer: <T extends {
3
3
  name: string;
4
4
  value: string;
package/dist/index.d.ts CHANGED
@@ -11,11 +11,11 @@ export { addTarget, addTargetClient } from './targets/targets';
11
11
  *
12
12
  * Then, in addition to that, it really adds to complexity with TypeScript (TypeScript takes this constraint very very seriously) in a way that's not actually super useful. So, we treat this object as though it could have both or either of `params` and/or `text`.
13
13
  */
14
- declare type PostDataBase = PostDataCommon & {
14
+ type PostDataBase = PostDataCommon & {
15
15
  text?: string;
16
16
  params?: Param[];
17
17
  };
18
- export declare type HarRequest = Omit<NpmHarRequest, 'postData'> & {
18
+ export type HarRequest = Omit<NpmHarRequest, 'postData'> & {
19
19
  postData: PostDataBase;
20
20
  };
21
21
  export interface RequestExtras {
@@ -31,7 +31,7 @@ export interface RequestExtras {
31
31
  cookiesObj: ReducedHelperObject;
32
32
  allHeaders: ReducedHelperObject;
33
33
  }
34
- export declare type Request = HarRequest & RequestExtras;
34
+ export type Request = HarRequest & RequestExtras;
35
35
  interface Entry {
36
36
  request: Partial<HarRequest>;
37
37
  }
package/dist/index.js CHANGED
@@ -43,7 +43,6 @@ var event_stream_1 = require("event-stream");
43
43
  var form_data_1 = __importDefault(require("form-data"));
44
44
  var qs_1 = require("qs");
45
45
  var form_data_2 = require("./helpers/form-data");
46
- var har_validator_1 = require("./helpers/har-validator");
47
46
  var headers_1 = require("./helpers/headers");
48
47
  var reducer_1 = require("./helpers/reducer");
49
48
  var targets_1 = require("./targets/targets");
@@ -279,9 +278,7 @@ var HTTPSnippet = /** @class */ (function () {
279
278
  if (req.postData && !req.postData.mimeType) {
280
279
  req.postData.mimeType = 'application/octet-stream';
281
280
  }
282
- if ((0, har_validator_1.validateHarRequest)(req)) {
283
- _this.requests.push(_this.prepare(req, options));
284
- }
281
+ _this.requests.push(_this.prepare(req, options));
285
282
  });
286
283
  }
287
284
  return HTTPSnippet;
@@ -1,3 +1,3 @@
1
1
  import type { Converter } from '../targets';
2
- export declare type PowershellCommand = 'Invoke-RestMethod' | 'Invoke-WebRequest';
2
+ export type PowershellCommand = 'Invoke-RestMethod' | 'Invoke-WebRequest';
3
3
  export declare const generatePowershellConvert: (command: PowershellCommand) => Converter<any>;
@@ -1,20 +1,20 @@
1
1
  import type { Request } from '..';
2
2
  import type { CodeBuilderOptions } from '../helpers/code-builder';
3
3
  import type { Merge } from 'type-fest';
4
- export declare type TargetId = keyof typeof targets;
5
- export declare type ClientId = string;
4
+ export type TargetId = keyof typeof targets;
5
+ export type ClientId = string;
6
6
  export interface ClientInfo {
7
7
  key: ClientId;
8
8
  title: string;
9
9
  link: string;
10
10
  description: string;
11
11
  }
12
- export declare type Converter<T extends Record<string, any>> = (request: Request, options?: Merge<CodeBuilderOptions, T>) => string;
12
+ export type Converter<T extends Record<string, any>> = (request: Request, options?: Merge<CodeBuilderOptions, T>) => string;
13
13
  export interface Client<T extends Record<string, any> = Record<string, any>> {
14
14
  info: ClientInfo;
15
15
  convert: Converter<T>;
16
16
  }
17
- export declare type Extension = `.${string}` | null;
17
+ export type Extension = `.${string}` | null;
18
18
  export interface TargetInfo {
19
19
  key: TargetId;
20
20
  title: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.1.0",
2
+ "version": "5.0.0",
3
3
  "name": "@readme/httpsnippet",
4
4
  "description": "HTTP Request snippet generator for *most* languages",
5
5
  "homepage": "https://github.com/readmeio/httpsnippet",
@@ -57,28 +57,26 @@
57
57
  "test": "jest --coverage"
58
58
  },
59
59
  "devDependencies": {
60
- "@readme/eslint-config": "^10.1.0",
60
+ "@readme/eslint-config": "^10.3.2",
61
61
  "@types/eslint": "^8.4.1",
62
62
  "@types/event-stream": "^4.0.0",
63
63
  "@types/har-format": "^1.2.8",
64
64
  "@types/jest": "^28.1.6",
65
- "@types/node": "^18.6.3",
65
+ "@types/node": "^18.11.18",
66
66
  "@types/qs": "^6.9.7",
67
- "@types/stringify-object": "^4.0.1",
68
- "eslint": "^8.19.0",
67
+ "@types/stringify-object": "^4.0.2",
68
+ "eslint": "^8.31.0",
69
69
  "glob": "^8.0.1",
70
70
  "jest": "^28.0.3",
71
- "prettier": "^2.7.1",
71
+ "prettier": "^2.8.1",
72
72
  "require-directory": "^2.1.1",
73
73
  "ts-jest": "^28.0.5",
74
- "type-fest": "^3.0.0",
75
- "typescript": "^4.6.3"
74
+ "type-fest": "^3.5.0",
75
+ "typescript": "^4.9.4"
76
76
  },
77
77
  "dependencies": {
78
- "ajv": "^6.12.6",
79
78
  "event-stream": "4.0.1",
80
79
  "form-data": "^4.0.0",
81
- "har-schema": "^2.0.0",
82
80
  "qs": "^6.10.1",
83
81
  "stringify-object": "^3.3.0"
84
82
  },
@@ -1,9 +0,0 @@
1
- import type { ErrorObject } from 'ajv';
2
- import type { Request } from 'har-format';
3
- export declare class HARError extends Error {
4
- name: string;
5
- message: string;
6
- errors: ErrorObject[];
7
- constructor(errors: ErrorObject[]);
8
- }
9
- export declare const validateHarRequest: (request: any) => request is Request;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- exports.__esModule = true;
44
- exports.validateHarRequest = exports.HARError = void 0;
45
- var ajv_1 = __importDefault(require("ajv"));
46
- var schema = __importStar(require("har-schema"));
47
- var HARError = /** @class */ (function (_super) {
48
- __extends(HARError, _super);
49
- function HARError(errors) {
50
- var _this = _super.call(this) || this;
51
- _this.name = 'HARError';
52
- _this.message = 'validation failed';
53
- _this.errors = [];
54
- _this.errors = errors;
55
- Error.captureStackTrace(_this, _this.constructor);
56
- return _this;
57
- }
58
- return HARError;
59
- }(Error));
60
- exports.HARError = HARError;
61
- var ajv = new ajv_1["default"]({
62
- allErrors: true
63
- });
64
- ajv.addSchema(schema);
65
- var validateHarRequest = function (request) {
66
- var validate = ajv.getSchema('request.json');
67
- if (!validate) {
68
- throw new Error('failed to find HAR request schema');
69
- }
70
- var valid = validate(request);
71
- if (!valid && validate.errors) {
72
- throw new HARError(validate.errors);
73
- }
74
- return true;
75
- };
76
- exports.validateHarRequest = validateHarRequest;