New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@har-sdk/core

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@har-sdk/core - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

2

dist/bundle.esm5.js

@@ -1,2 +0,2 @@

import{load as t,YAMLException as e}from"js-yaml";export*from"openapi-types";class r{constructor(t){this.syntaxErrorDetailsExtractor=t}load(t){this.source=t,this.error=void 0;try{return this.parse()}catch(t){throw t instanceof Error&&(this.error=t),t}}getSyntaxErrorDetails(){return this.error&&(this.isSupportedError(this.error)?this.syntaxErrorDetailsExtractor.extract(this.error,this.source):{message:this.error.message})}}class s{get lineOffsets(){if(!this._lineOffsets){let t=0;this._lineOffsets=[0,...(this.source||"").split("\n").map((e=>t+=e.length+1))]}return this._lineOffsets}extract(t,e){this.source=e,this._lineOffsets=void 0;const r=this.extractMessage(t),s=this.extractOffset(t),o=this.extractSnippet(t);return{message:r,...void 0!==s?{offset:s}:{},...void 0!==o?{snippet:o}:{}}}extractSnippet(t){}extractMessage(t){return t.message}calculateOffset(t,e){return t<=this.lineOffsets.length?this.lineOffsets[t-1]+e-1:this.source.length}}class o extends s{constructor(){super(...arguments),this.LOCATION_PATTERNS=[{pattern:/at position (\d+)$/,positionExtractor:([,t])=>+t},{pattern:/at line (\d+) column (\d+)/,positionExtractor:([,t,e])=>({lineNumber:+t,columnNumber:+e})}]}extractOffset(t){const e="lineNumber"in t&&"columnNumber"in t?t:this.extractByLocationPatterns(t.message);return"number"==typeof e?e:e&&this.calculateOffset(e.lineNumber,e.columnNumber)}extractMessage(t){return t.message.replace(/^JSON.parse: /,"").replace(/ at line \d+ column \d+ of the JSON data$/,"").replace(/ at position \d+$/,"")}extractByLocationPatterns(t){for(let e=0;e<this.LOCATION_PATTERNS.length;++e){const r=this.LOCATION_PATTERNS[e],s=t.match(r.pattern);if(s)return r.positionExtractor(s)}}}class n extends s{constructor(){super(...arguments),this.LOCATION_PATTERN=/\((\d+):(\d+)\)$/}extractMessage(t){const[e]=t.message.split("\n");return e.replace(/^YAMLException: /,"").replace(this.LOCATION_PATTERN,"").trim()}extractOffset(t){const[e]=t.message.split("\n"),r=e.match(this.LOCATION_PATTERN);return r?this.calculateOffset(+r[1],+r[2]):void 0}extractSnippet(t){return t.message.split("\n").slice(2).join("\n")}}class a extends r{constructor(){super(new o)}parse(){return JSON.parse(this.source)}isSupportedError(t){return t instanceof SyntaxError}}class i extends r{constructor(){super(new n)}parse(){return t(this.source,{json:!0})}isSupportedError(t){return t instanceof e}}class c{getLoader(t){switch(t){case"json":return new a;case"yaml":return new i}}}class l{constructor(){this.docFormats=["json","yaml"],this.loaderFactory=new c,this.loaders=new Map}async import(t,e){const r=this.load(t.trim(),e);if(r&&this.isSupported(r.doc)){const{format:t,doc:e}=r;return{doc:e,name:this.fileName({format:t,doc:e}),format:t,type:this.type}}}getErrorDetails(t){var e;return null===(e=this.getLoader(t))||void 0===e?void 0:e.getSyntaxErrorDetails()}fileName(t){}load(t,e){return this.initLoaders(),this.docFormats.reduce(((r,s)=>{if(r||e&&e!==s)return r;try{const e=this.getLoader(s).load(t);if(e)return{doc:e,format:s}}catch(t){}}),void 0)}initLoaders(){this.loaders.clear(),this.docFormats.forEach((t=>this.loaders.set(t,this.loaderFactory.getLoader(t))))}getLoader(t){return this.loaders.get(t)}}class u extends l{constructor(){super(),this.SUPPORTED_HAR_VERSION=/^1\.\d+$/}get type(){return"har"}isSupported(t){var e;return!!((null===(e=null==t?void 0:t.log)||void 0===e?void 0:e.version)&&Array.isArray(t.log.entries)&&this.SUPPORTED_HAR_VERSION.test(t.log.version))}}class p extends l{constructor(){super()}fileName({doc:t,format:e}){return`${[t.info.title,t.info.version].map((t=>t.trim())).join(" ")}.${e}`}}class h extends p{constructor(){super(),this.SUPPORTED_SWAGGER_VERSION="2.0"}get type(){return"oasv2"}isSupported(t){var e;return(null===(e=null==t?void 0:t.swagger)||void 0===e?void 0:e.trim())===this.SUPPORTED_SWAGGER_VERSION}}class d extends p{constructor(){super(),this.SUPPORTED_OPENAPI_VERSION=/^3\.0\.\d+$/}get type(){return"oasv3"}isSupported(t){return!(!(null==t?void 0:t.openapi)||!this.SUPPORTED_OPENAPI_VERSION.test(t.openapi))}}class m extends l{constructor(){super(),this.POSTMAN_SCHEMAS=new Set(["https://schema.getpostman.com/json/collection/v2.0.0/collection.json","https://schema.getpostman.com/json/collection/v2.1.0/collection.json"])}get type(){return"postman"}isSupported(t){var e;const r=null===(e=null==t?void 0:t.info)||void 0===e?void 0:e.schema;return this.POSTMAN_SCHEMAS.has(null==r?void 0:r.trim().toLowerCase())}fileName({doc:t,format:e}){return t.info.name?`${t.info.name.trim()}.${e}`:void 0}}const f=void 0!==global.window?global.window.URL:require("url").URL,O=t=>t.replace(/\/$/,""),g=t=>t.replace(/^\//,""),S=t=>{const e=new f((t=>(!/^\/{2}/.test(t)&&/^\.+\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,"https://")),t))(t));try{e.pathname=(r=e.pathname,decodeURI(O(r.replace(/((?!:).|^)\/{2,}/g,((t,e)=>/^(?!\/)/g.test(e)?`${e}/`:"/")))))}catch{}var r;e.searchParams.sort(),e.hostname=e.hostname.replace(/\.$/,"");let s=e.toString();return"/"===e.pathname&&""===e.hash&&(s=O(s)),s},E=t=>new f(t);class x{constructor(t=[new u,new d,new m,new h]){this.importers=t}async import(t,e){let r;try{const s=this.importers.map((r=>r.import(t,e)));r=await((t,e)=>{const r=t.map((t=>new Promise(((r,s)=>t.then((t=>!!e(t)&&r(t)),s)))));return r.push(Promise.all(t).then((()=>{}))),Promise.race(r)})(s,(t=>!!t))}catch{}return r}}export{u as HARImporter,h as OASV2Importer,d as OASV3Importer,m as PostmanImporter,x as SpecImporter,S as normalizeUrl,E as parseUrl,g as removeLeadingSlash,O as removeTrailingSlash};
import{load as t,YAMLException as e}from"js-yaml";export*from"openapi-types";class r{constructor(t){this.syntaxErrorDetailsExtractor=t}load(t){this.source=t,this.error=void 0;try{return this.parse()}catch(t){throw t instanceof Error&&(this.error=t),t}}getSyntaxErrorDetails(){return this.error&&(this.isSupportedError(this.error)?this.syntaxErrorDetailsExtractor.extract(this.error,this.source):{message:this.error.message})}}class s{get lineOffsets(){if(!this._lineOffsets){let t=0;this._lineOffsets=[0,...(this.source||"").split("\n").map((e=>t+=e.length+1))]}return this._lineOffsets}extract(t,e){this.source=e,this._lineOffsets=void 0;const r=this.extractMessage(t),s=this.extractOffset(t),o=this.extractSnippet(t);return{message:r,...void 0!==s?{offset:s}:{},...void 0!==o?{snippet:o}:{}}}extractSnippet(t){}extractMessage(t){return t.message}calculateOffset(t,e){return t<=this.lineOffsets.length?this.lineOffsets[t-1]+e-1:this.source.length}}class o extends s{constructor(){super(...arguments),this.LOCATION_PATTERNS=[{pattern:/at position (\d+)$/,positionExtractor:([,t])=>+t},{pattern:/at line (\d+) column (\d+)/,positionExtractor:([,t,e])=>({lineNumber:+t,columnNumber:+e})}]}extractOffset(t){const e="lineNumber"in t&&"columnNumber"in t?t:this.extractByLocationPatterns(t.message);return"number"==typeof e?e:e&&this.calculateOffset(e.lineNumber,e.columnNumber)}extractMessage(t){return t.message.replace(/^JSON.parse: /,"").replace(/ at line \d+ column \d+ of the JSON data$/,"").replace(/ at position \d+$/,"")}extractByLocationPatterns(t){for(let e=0;e<this.LOCATION_PATTERNS.length;++e){const r=this.LOCATION_PATTERNS[e],s=t.match(r.pattern);if(s)return r.positionExtractor(s)}}}class n extends s{constructor(){super(...arguments),this.LOCATION_PATTERN=/\((\d+):(\d+)\)$/}extractMessage(t){const[e]=t.message.split("\n");return e.replace(/^YAMLException: /,"").replace(this.LOCATION_PATTERN,"").trim()}extractOffset(t){const[e]=t.message.split("\n"),r=e.match(this.LOCATION_PATTERN);return r?this.calculateOffset(+r[1],+r[2]):void 0}extractSnippet(t){return t.message.split("\n").slice(2).join("\n")}}class i extends r{constructor(){super(new o)}parse(){return JSON.parse(this.source)}isSupportedError(t){return t instanceof SyntaxError}}class a extends r{constructor(){super(new n)}parse(){return t(this.source,{json:!0})}isSupportedError(t){return t instanceof e}}class c{getLoader(t){switch(t){case"json":return new i;case"yaml":return new a}}}class l{constructor(){this.docFormats=["json","yaml"],this.loaderFactory=new c,this.loaders=new Map}async import(t,e){const r=this.load(t.trim(),e);if(r&&this.isSupported(r.doc)){const{format:t,doc:e}=r;return{doc:e,name:this.fileName({format:t,doc:e}),format:t,type:this.type}}}getErrorDetails(t){var e;return null===(e=this.getLoader(t))||void 0===e?void 0:e.getSyntaxErrorDetails()}fileName(t){}load(t,e){return this.initLoaders(),this.docFormats.reduce(((r,s)=>{if(r||e&&e!==s)return r;try{const e=this.getLoader(s).load(t);if(e)return{doc:e,format:s}}catch(t){}}),void 0)}initLoaders(){this.loaders.clear(),this.docFormats.forEach((t=>this.loaders.set(t,this.loaderFactory.getLoader(t))))}getLoader(t){return this.loaders.get(t)}}class u extends l{constructor(){super(),this.SUPPORTED_HAR_VERSION=/^1\.\d+$/}get type(){return"har"}isSupported(t){var e;return!!((null===(e=null==t?void 0:t.log)||void 0===e?void 0:e.version)&&Array.isArray(t.log.entries)&&this.SUPPORTED_HAR_VERSION.test(t.log.version))}}class p extends l{constructor(){super()}fileName({doc:t,format:e}){return`${[t.info.title,t.info.version].map((t=>t.trim())).join(" ")}.${e}`}}class h extends p{constructor(){super(),this.SUPPORTED_SWAGGER_VERSION="2.0"}get type(){return"oasv2"}isSupported(t){var e;return(null===(e=null==t?void 0:t.swagger)||void 0===e?void 0:e.trim())===this.SUPPORTED_SWAGGER_VERSION}}class d extends p{constructor(){super(),this.SUPPORTED_OPENAPI_VERSION=/^3\.0\.\d+$/}get type(){return"oasv3"}isSupported(t){return!(!(null==t?void 0:t.openapi)||!this.SUPPORTED_OPENAPI_VERSION.test(t.openapi))}}class m extends l{constructor(){super(),this.POSTMAN_SCHEMAS=new Set(["https://schema.getpostman.com/json/collection/v2.0.0/collection.json","https://schema.getpostman.com/json/collection/v2.1.0/collection.json"])}get type(){return"postman"}isSupported(t){var e;const r=null===(e=null==t?void 0:t.info)||void 0===e?void 0:e.schema;return this.POSTMAN_SCHEMAS.has(null==r?void 0:r.trim().toLowerCase())}fileName({doc:t,format:e}){return t.info.name?`${t.info.name.trim()}.${e}`:void 0}}const f=void 0!==global.window?global.window.URL:require("url").URL,g=t=>t.replace(/\/$/,""),O=t=>t.replace(/^\//,""),E=t=>{const e=new f(t);if(!S(e))throw new TypeError(`Invalid URL: ${e}`);return e},S=t=>{let e;try{e="string"==typeof t?E(t):t}catch{}return!!(e&&e.hostname&&e.origin&&"null"!==e.origin)},x=t=>{const e=E((t=>(!/^\/{2}/.test(t)&&/^\.+\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,"https://")),t))(t));try{e.pathname=(r=e.pathname,decodeURI(g(r.replace(/((?!:).|^)\/{2,}/g,((t,e)=>/^(?!\/)/g.test(e)?`${e}/`:"/")))))}catch{}var r;e.searchParams.sort(),e.hostname=e.hostname.replace(/\.$/,"");let s=e.toString();return"/"===e.pathname&&""===e.hash&&(s=g(s)),s};class N{constructor(t=[new u,new d,new m,new h]){this.importers=t}async import(t,e){let r;try{const s=this.importers.map((r=>r.import(t,e)));r=await((t,e)=>{const r=t.map((t=>new Promise(((r,s)=>t.then((t=>!!e(t)&&r(t)),s)))));return r.push(Promise.all(t).then((()=>{}))),Promise.race(r)})(s,(t=>!!t))}catch{}return r}}export{u as HARImporter,h as OASV2Importer,d as OASV3Importer,m as PostmanImporter,N as SpecImporter,x as normalizeUrl,E as parseUrl,O as removeLeadingSlash,g as removeTrailingSlash,S as validateUrl};
//# sourceMappingURL=bundle.esm5.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("js-yaml"),require("openapi-types")):"function"==typeof define&&define.amd?define(["exports","js-yaml","openapi-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@har-sdk/core"]={},t.jsYaml,t.openapiTypes)}(this,(function(t,e,r){class s{constructor(t){this.syntaxErrorDetailsExtractor=t}load(t){this.source=t,this.error=void 0;try{return this.parse()}catch(t){throw t instanceof Error&&(this.error=t),t}}getSyntaxErrorDetails(){return this.error&&(this.isSupportedError(this.error)?this.syntaxErrorDetailsExtractor.extract(this.error,this.source):{message:this.error.message})}}class o{get lineOffsets(){if(!this._lineOffsets){let t=0;this._lineOffsets=[0,...(this.source||"").split("\n").map((e=>t+=e.length+1))]}return this._lineOffsets}extract(t,e){this.source=e,this._lineOffsets=void 0;const r=this.extractMessage(t),s=this.extractOffset(t),o=this.extractSnippet(t);return{message:r,...void 0!==s?{offset:s}:{},...void 0!==o?{snippet:o}:{}}}extractSnippet(t){}extractMessage(t){return t.message}calculateOffset(t,e){return t<=this.lineOffsets.length?this.lineOffsets[t-1]+e-1:this.source.length}}class n extends o{constructor(){super(...arguments),this.LOCATION_PATTERNS=[{pattern:/at position (\d+)$/,positionExtractor:([,t])=>+t},{pattern:/at line (\d+) column (\d+)/,positionExtractor:([,t,e])=>({lineNumber:+t,columnNumber:+e})}]}extractOffset(t){const e="lineNumber"in t&&"columnNumber"in t?t:this.extractByLocationPatterns(t.message);return"number"==typeof e?e:e&&this.calculateOffset(e.lineNumber,e.columnNumber)}extractMessage(t){return t.message.replace(/^JSON.parse: /,"").replace(/ at line \d+ column \d+ of the JSON data$/,"").replace(/ at position \d+$/,"")}extractByLocationPatterns(t){for(let e=0;e<this.LOCATION_PATTERNS.length;++e){const r=this.LOCATION_PATTERNS[e],s=t.match(r.pattern);if(s)return r.positionExtractor(s)}}}class i extends o{constructor(){super(...arguments),this.LOCATION_PATTERN=/\((\d+):(\d+)\)$/}extractMessage(t){const[e]=t.message.split("\n");return e.replace(/^YAMLException: /,"").replace(this.LOCATION_PATTERN,"").trim()}extractOffset(t){const[e]=t.message.split("\n"),r=e.match(this.LOCATION_PATTERN);return r?this.calculateOffset(+r[1],+r[2]):void 0}extractSnippet(t){return t.message.split("\n").slice(2).join("\n")}}class a extends s{constructor(){super(new n)}parse(){return JSON.parse(this.source)}isSupportedError(t){return t instanceof SyntaxError}}class c extends s{constructor(){super(new i)}parse(){return e.load(this.source,{json:!0})}isSupportedError(t){return t instanceof e.YAMLException}}class l{getLoader(t){switch(t){case"json":return new a;case"yaml":return new c}}}class p{constructor(){this.docFormats=["json","yaml"],this.loaderFactory=new l,this.loaders=new Map}async import(t,e){const r=this.load(t.trim(),e);if(r&&this.isSupported(r.doc)){const{format:t,doc:e}=r;return{doc:e,name:this.fileName({format:t,doc:e}),format:t,type:this.type}}}getErrorDetails(t){var e;return null===(e=this.getLoader(t))||void 0===e?void 0:e.getSyntaxErrorDetails()}fileName(t){}load(t,e){return this.initLoaders(),this.docFormats.reduce(((r,s)=>{if(r||e&&e!==s)return r;try{const e=this.getLoader(s).load(t);if(e)return{doc:e,format:s}}catch(t){}}),void 0)}initLoaders(){this.loaders.clear(),this.docFormats.forEach((t=>this.loaders.set(t,this.loaderFactory.getLoader(t))))}getLoader(t){return this.loaders.get(t)}}class u extends p{constructor(){super(),this.SUPPORTED_HAR_VERSION=/^1\.\d+$/}get type(){return"har"}isSupported(t){var e;return!!((null===(e=null==t?void 0:t.log)||void 0===e?void 0:e.version)&&Array.isArray(t.log.entries)&&this.SUPPORTED_HAR_VERSION.test(t.log.version))}}class h extends p{constructor(){super()}fileName({doc:t,format:e}){return`${[t.info.title,t.info.version].map((t=>t.trim())).join(" ")}.${e}`}}class d extends h{constructor(){super(),this.SUPPORTED_SWAGGER_VERSION="2.0"}get type(){return"oasv2"}isSupported(t){var e;return(null===(e=null==t?void 0:t.swagger)||void 0===e?void 0:e.trim())===this.SUPPORTED_SWAGGER_VERSION}}class m extends h{constructor(){super(),this.SUPPORTED_OPENAPI_VERSION=/^3\.0\.\d+$/}get type(){return"oasv3"}isSupported(t){return!(!(null==t?void 0:t.openapi)||!this.SUPPORTED_OPENAPI_VERSION.test(t.openapi))}}class f extends p{constructor(){super(),this.POSTMAN_SCHEMAS=new Set(["https://schema.getpostman.com/json/collection/v2.0.0/collection.json","https://schema.getpostman.com/json/collection/v2.1.0/collection.json"])}get type(){return"postman"}isSupported(t){var e;const r=null===(e=null==t?void 0:t.info)||void 0===e?void 0:e.schema;return this.POSTMAN_SCHEMAS.has(null==r?void 0:r.trim().toLowerCase())}fileName({doc:t,format:e}){return t.info.name?`${t.info.name.trim()}.${e}`:void 0}}const O=void 0!==global.window?global.window.URL:require("url").URL,g=t=>t.replace(/\/$/,"");t.HARImporter=u,t.OASV2Importer=d,t.OASV3Importer=m,t.PostmanImporter=f,t.SpecImporter=class{constructor(t=[new u,new m,new f,new d]){this.importers=t}async import(t,e){let r;try{const s=this.importers.map((r=>r.import(t,e)));r=await((t,e)=>{const r=t.map((t=>new Promise(((r,s)=>t.then((t=>!!e(t)&&r(t)),s)))));return r.push(Promise.all(t).then((()=>{}))),Promise.race(r)})(s,(t=>!!t))}catch{}return r}},t.normalizeUrl=t=>{const e=new O((t=>(!/^\/{2}/.test(t)&&/^\.+\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,"https://")),t))(t));try{e.pathname=(r=e.pathname,decodeURI(g(r.replace(/((?!:).|^)\/{2,}/g,((t,e)=>/^(?!\/)/g.test(e)?`${e}/`:"/")))))}catch{}var r;e.searchParams.sort(),e.hostname=e.hostname.replace(/\.$/,"");let s=e.toString();return"/"===e.pathname&&""===e.hash&&(s=g(s)),s},t.parseUrl=t=>new O(t),t.removeLeadingSlash=t=>t.replace(/^\//,""),t.removeTrailingSlash=g,Object.keys(r).forEach((function(e){"default"===e||t.hasOwnProperty(e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[e]}})}))}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("js-yaml"),require("openapi-types")):"function"==typeof define&&define.amd?define(["exports","js-yaml","openapi-types"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@har-sdk/core"]={},t.jsYaml,t.openapiTypes)}(this,(function(t,e,r){class s{constructor(t){this.syntaxErrorDetailsExtractor=t}load(t){this.source=t,this.error=void 0;try{return this.parse()}catch(t){throw t instanceof Error&&(this.error=t),t}}getSyntaxErrorDetails(){return this.error&&(this.isSupportedError(this.error)?this.syntaxErrorDetailsExtractor.extract(this.error,this.source):{message:this.error.message})}}class o{get lineOffsets(){if(!this._lineOffsets){let t=0;this._lineOffsets=[0,...(this.source||"").split("\n").map((e=>t+=e.length+1))]}return this._lineOffsets}extract(t,e){this.source=e,this._lineOffsets=void 0;const r=this.extractMessage(t),s=this.extractOffset(t),o=this.extractSnippet(t);return{message:r,...void 0!==s?{offset:s}:{},...void 0!==o?{snippet:o}:{}}}extractSnippet(t){}extractMessage(t){return t.message}calculateOffset(t,e){return t<=this.lineOffsets.length?this.lineOffsets[t-1]+e-1:this.source.length}}class n extends o{constructor(){super(...arguments),this.LOCATION_PATTERNS=[{pattern:/at position (\d+)$/,positionExtractor:([,t])=>+t},{pattern:/at line (\d+) column (\d+)/,positionExtractor:([,t,e])=>({lineNumber:+t,columnNumber:+e})}]}extractOffset(t){const e="lineNumber"in t&&"columnNumber"in t?t:this.extractByLocationPatterns(t.message);return"number"==typeof e?e:e&&this.calculateOffset(e.lineNumber,e.columnNumber)}extractMessage(t){return t.message.replace(/^JSON.parse: /,"").replace(/ at line \d+ column \d+ of the JSON data$/,"").replace(/ at position \d+$/,"")}extractByLocationPatterns(t){for(let e=0;e<this.LOCATION_PATTERNS.length;++e){const r=this.LOCATION_PATTERNS[e],s=t.match(r.pattern);if(s)return r.positionExtractor(s)}}}class i extends o{constructor(){super(...arguments),this.LOCATION_PATTERN=/\((\d+):(\d+)\)$/}extractMessage(t){const[e]=t.message.split("\n");return e.replace(/^YAMLException: /,"").replace(this.LOCATION_PATTERN,"").trim()}extractOffset(t){const[e]=t.message.split("\n"),r=e.match(this.LOCATION_PATTERN);return r?this.calculateOffset(+r[1],+r[2]):void 0}extractSnippet(t){return t.message.split("\n").slice(2).join("\n")}}class a extends s{constructor(){super(new n)}parse(){return JSON.parse(this.source)}isSupportedError(t){return t instanceof SyntaxError}}class c extends s{constructor(){super(new i)}parse(){return e.load(this.source,{json:!0})}isSupportedError(t){return t instanceof e.YAMLException}}class l{getLoader(t){switch(t){case"json":return new a;case"yaml":return new c}}}class p{constructor(){this.docFormats=["json","yaml"],this.loaderFactory=new l,this.loaders=new Map}async import(t,e){const r=this.load(t.trim(),e);if(r&&this.isSupported(r.doc)){const{format:t,doc:e}=r;return{doc:e,name:this.fileName({format:t,doc:e}),format:t,type:this.type}}}getErrorDetails(t){var e;return null===(e=this.getLoader(t))||void 0===e?void 0:e.getSyntaxErrorDetails()}fileName(t){}load(t,e){return this.initLoaders(),this.docFormats.reduce(((r,s)=>{if(r||e&&e!==s)return r;try{const e=this.getLoader(s).load(t);if(e)return{doc:e,format:s}}catch(t){}}),void 0)}initLoaders(){this.loaders.clear(),this.docFormats.forEach((t=>this.loaders.set(t,this.loaderFactory.getLoader(t))))}getLoader(t){return this.loaders.get(t)}}class u extends p{constructor(){super(),this.SUPPORTED_HAR_VERSION=/^1\.\d+$/}get type(){return"har"}isSupported(t){var e;return!!((null===(e=null==t?void 0:t.log)||void 0===e?void 0:e.version)&&Array.isArray(t.log.entries)&&this.SUPPORTED_HAR_VERSION.test(t.log.version))}}class h extends p{constructor(){super()}fileName({doc:t,format:e}){return`${[t.info.title,t.info.version].map((t=>t.trim())).join(" ")}.${e}`}}class d extends h{constructor(){super(),this.SUPPORTED_SWAGGER_VERSION="2.0"}get type(){return"oasv2"}isSupported(t){var e;return(null===(e=null==t?void 0:t.swagger)||void 0===e?void 0:e.trim())===this.SUPPORTED_SWAGGER_VERSION}}class m extends h{constructor(){super(),this.SUPPORTED_OPENAPI_VERSION=/^3\.0\.\d+$/}get type(){return"oasv3"}isSupported(t){return!(!(null==t?void 0:t.openapi)||!this.SUPPORTED_OPENAPI_VERSION.test(t.openapi))}}class f extends p{constructor(){super(),this.POSTMAN_SCHEMAS=new Set(["https://schema.getpostman.com/json/collection/v2.0.0/collection.json","https://schema.getpostman.com/json/collection/v2.1.0/collection.json"])}get type(){return"postman"}isSupported(t){var e;const r=null===(e=null==t?void 0:t.info)||void 0===e?void 0:e.schema;return this.POSTMAN_SCHEMAS.has(null==r?void 0:r.trim().toLowerCase())}fileName({doc:t,format:e}){return t.info.name?`${t.info.name.trim()}.${e}`:void 0}}const g=void 0!==global.window?global.window.URL:require("url").URL,O=t=>t.replace(/\/$/,""),S=t=>{const e=new g(t);if(!E(e))throw new TypeError(`Invalid URL: ${e}`);return e},E=t=>{let e;try{e="string"==typeof t?S(t):t}catch{}return!!(e&&e.hostname&&e.origin&&"null"!==e.origin)};t.HARImporter=u,t.OASV2Importer=d,t.OASV3Importer=m,t.PostmanImporter=f,t.SpecImporter=class{constructor(t=[new u,new m,new f,new d]){this.importers=t}async import(t,e){let r;try{const s=this.importers.map((r=>r.import(t,e)));r=await((t,e)=>{const r=t.map((t=>new Promise(((r,s)=>t.then((t=>!!e(t)&&r(t)),s)))));return r.push(Promise.all(t).then((()=>{}))),Promise.race(r)})(s,(t=>!!t))}catch{}return r}},t.normalizeUrl=t=>{const e=S((t=>(!/^\/{2}/.test(t)&&/^\.+\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,"https://")),t))(t));try{e.pathname=(r=e.pathname,decodeURI(O(r.replace(/((?!:).|^)\/{2,}/g,((t,e)=>/^(?!\/)/g.test(e)?`${e}/`:"/")))))}catch{}var r;e.searchParams.sort(),e.hostname=e.hostname.replace(/\.$/,"");let s=e.toString();return"/"===e.pathname&&""===e.hash&&(s=O(s)),s},t.parseUrl=S,t.removeLeadingSlash=t=>t.replace(/^\//,""),t.removeTrailingSlash=O,t.validateUrl=E,Object.keys(r).forEach((function(e){"default"===e||t.hasOwnProperty(e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[e]}})}))}));
//# sourceMappingURL=bundle.umd.js.map
export * from './importers';
export { SyntaxErrorDetails } from './loaders';
export * from './types';
export { normalizeUrl, parseUrl, removeLeadingSlash, removeTrailingSlash } from './utils';
export { normalizeUrl, parseUrl, validateUrl, removeLeadingSlash, removeTrailingSlash } from './utils';
export * from './importers';
export * from './types';
export { normalizeUrl, parseUrl, removeLeadingSlash, removeTrailingSlash } from './utils';
export { normalizeUrl, parseUrl, validateUrl, removeLeadingSlash, removeTrailingSlash } from './utils';
//# sourceMappingURL=index.js.map
declare const URL: any;
export declare const removeTrailingSlash: (path: string) => string;
export declare const removeLeadingSlash: (path: string) => string;
export declare const parseUrl: (value: string) => typeof URL;
export declare const validateUrl: (value: string | typeof URL) => boolean;
export declare const normalizeUrl: (value: string) => string;
export declare const parseUrl: (value: string) => typeof URL;
export {};

@@ -17,4 +17,22 @@ const URL = typeof global.window !== 'undefined'

};
export const parseUrl = (value) => {
const url = new URL(value);
if (!validateUrl(url)) {
throw new TypeError(`Invalid URL: ${url}`);
}
return url;
};
export const validateUrl = (value) => {
let url;
try {
url = typeof value === 'string' ? parseUrl(value) : value;
}
catch {
// noop
}
// verify an opaque origin https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin
return !!(url && url.hostname && url.origin && url.origin !== 'null');
};
export const normalizeUrl = (value) => {
const url = new URL(prependProtocolIfNecessary(value));
const url = parseUrl(prependProtocolIfNecessary(value));
try {

@@ -34,3 +52,2 @@ url.pathname = normalizePathName(url.pathname);

};
export const parseUrl = (value) => new URL(value);
//# sourceMappingURL=url.js.map
{
"name": "@har-sdk/core",
"version": "1.3.0",
"version": "1.4.0",
"private": false,

@@ -5,0 +5,0 @@ "description": "The base package can be used to import specification files (i.e. HAR, OAS and Postman Collection) and detect their type.",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc