@http-forge/core 0.7.2 → 1.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/LICENSE +21 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Henry Huang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -638,7 +638,7 @@ fragment TypeRef on __Type {
|
|
|
638
638
|
kind name
|
|
639
639
|
ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } }
|
|
640
640
|
}
|
|
641
|
-
`.trim(),ys=class{constructor(e){this.httpClient=e}httpClient;schemaCache=new Map;async fetchSchema(e,t){let n={method:"POST",url:e,headers:{"Content-Type":"application/json",Accept:"application/json"
|
|
641
|
+
`.trim(),ys=class{constructor(e){this.httpClient=e}httpClient;schemaCache=new Map;async fetchSchema(e,t){let n={method:"POST",url:e,headers:{...t||{},"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:ay,operationName:"IntrospectionQuery"})},s=await this.httpClient.send(n);if(s.status<200||s.status>=300)throw new Error(`Introspection query failed with status ${s.status}: ${s.statusText}`);let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(i.errors&&i.errors.length>0){let a=i.errors.map(c=>c.message).join("; ");throw new Error(`Introspection query returned errors: ${a}`)}if(!i.data?.__schema)throw new Error("Invalid introspection response: missing __schema");let o=this.parseSchema(i.data.__schema,e);return this.schemaCache.set(e,o),o}getCachedSchema(e){return this.schemaCache.get(e)}extractOperations(e){let t=[],n=e.split(`
|
|
642
642
|
`),s=/^\s*(query|mutation|subscription)\s+(\w+)/;for(let i=0;i<n.length;i++){let o=n[i].match(s);o&&t.push({type:o[1],name:o[2],line:i+1})}return t.length===0&&e.trim().startsWith("{")&&t.push({type:"query",name:"(anonymous)",line:1}),t}clearCache(e){e?this.schemaCache.delete(e):this.schemaCache.clear()}schemaToSerializable(e){let t={};for(let[n,s]of e.types)t[n]=s;return{queryType:e.queryType,mutationType:e.mutationType,subscriptionType:e.subscriptionType,types:t,directives:e.directives,fetchedAt:e.fetchedAt,endpointUrl:e.endpointUrl}}parseSchema(e,t){let n=new Map;for(let i of e.types||[]){if(i.name.startsWith("__"))continue;let o={name:i.name,kind:i.kind,description:i.description||void 0,fields:(i.fields||[]).map(a=>this.parseField(a)),inputFields:(i.inputFields||[]).map(a=>this.parseArg(a)),enumValues:(i.enumValues||[]).map(a=>({name:a.name,description:a.description||void 0,isDeprecated:a.isDeprecated||!1,deprecationReason:a.deprecationReason||void 0})),interfaces:(i.interfaces||[]).map(a=>this.renderTypeRef(a)),possibleTypes:(i.possibleTypes||[]).map(a=>this.renderTypeRef(a))};n.set(o.name,o)}let s=(e.directives||[]).map(i=>({name:i.name,description:i.description||void 0,locations:i.locations||[],args:(i.args||[]).map(o=>this.parseArg(o))}));return{queryType:e.queryType?.name||"Query",mutationType:e.mutationType?.name||void 0,subscriptionType:e.subscriptionType?.name||void 0,types:n,directives:s,fetchedAt:Date.now(),endpointUrl:t}}parseField(e){return{name:e.name,type:this.renderTypeRef(e.type),args:(e.args||[]).map(t=>this.parseArg(t)),description:e.description||void 0,isDeprecated:e.isDeprecated||!1,deprecationReason:e.deprecationReason||void 0}}parseArg(e){return{name:e.name,type:this.renderTypeRef(e.type),defaultValue:e.defaultValue??void 0,description:e.description||void 0}}renderTypeRef(e){return e?e.kind==="NON_NULL"?`${this.renderTypeRef(e.ofType)}!`:e.kind==="LIST"?`[${this.renderTypeRef(e.ofType)}]`:e.name||"Unknown":"Unknown"}}});function pt(r){let e={};for(let[t,n]of Object.entries(r))gp.test(t)?e[t]=Array.isArray(n)?n.map(()=>Gt):Gt:e[t]=n;return e}function jl(r=[]){return r.map(e=>e&&typeof e=="object"&&e.name&&Kt.test(e.name)?{...e,value:Gt}:e)}function Ml(r){try{let e=new URL(r),t=!1;for(let[n]of e.searchParams)Kt.test(n)&&(e.searchParams.set(n,Gt),t=!0);return t?e.toString():r}catch{return r}}function $i(r){if(r==null)return r;if(Array.isArray(r))return r.map(t=>$i(t));if(typeof r!="object")return r;let e={};for(let[t,n]of Object.entries(r)){let s=Kt.test(t);n===null||typeof n!="object"?e[t]=s?Gt:n:s&&Array.isArray(n)?e[t]=n.map(i=>i===null||typeof i!="object"?Gt:$i(i)):e[t]=$i(n)}return e}function cy(r){try{let e=new URLSearchParams(r),t=!1;for(let[n]of e)Kt.test(n)&&(e.set(n,Gt),t=!0);return t?e.toString():r}catch{return r}}function yp(r){if(r==null)return r;if(typeof r=="object"&&!Buffer.isBuffer(r))return $i(r);if(typeof r=="string"){let e=r.trim();if(e.startsWith("{")||e.startsWith("["))try{let t=JSON.parse(e),n=$i(t);return JSON.stringify(n)}catch{}if(e.includes("=")&&!e.includes(`
|
|
643
643
|
`))return cy(e)}return r}function ly(r,e){let t=r;for(let n of e){if(n.length<mp)continue;let s=new Set([n]);for(let i of[encodeURI,encodeURIComponent])try{s.add(i(n))}catch{}for(let i of s)i.length<mp||!t.includes(i)||(t=t.split(i).join(Gt))}return t}function fr(r,e){if(e.length===0)return r;if(typeof r=="string")return ly(r,e);if(Array.isArray(r))return r.map(t=>fr(t,e));if(r!==null&&typeof r=="object"){let t=Object.getPrototypeOf(r);if(t!==Object.prototype&&t!==null)return r;let n={};for(let[s,i]of Object.entries(r))n[s]=fr(i,e);return n}return r}function Wo(r,e){let t=e??dr(r.sentRequest),n={...r,sentRequest:{...r.sentRequest,url:Ml(r.sentRequest.url),headers:pt(r.sentRequest.headers),body:r.sentRequest.body!=null?yp(r.sentRequest.body):r.sentRequest.body}};return fr(n,t)}function Go(r,e=[]){let t={...r,headers:pt(r.headers),cookies:r.cookies.map(n=>n&&typeof n=="object"&&n.name&&Kt.test(n.name)?{...n,value:Gt}:n)};return fr(t,e)}function Ko(r,e=[]){let t={...r,url:Ml(r.url),request:{...r.request,url:Ml(r.request.url),headers:pt(r.request.headers),query:pt(r.request.query),params:pt(r.request.params),body:r.request.body!=null?yp(r.request.body):r.request.body},response:{headers:pt(r.response.headers),body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies?jl(r.response.cookies):r.response.cookies}};return fr(t,e)}function On(r){return typeof r=="string"&&uy.test(r)}function pr(r){return r.replace(/\./g,"_").replace(/[^a-zA-Z0-9_]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").toLowerCase()}function vp(r){let e=[],t=new Set;function n(s){let i=s,o=2;for(;t.has(i);)i=`${s}_${o++}`;return t.add(i),i}if(r.url)try{let s=new URL(r.url.includes("://")?r.url:`http://placeholder${r.url.startsWith("/")?"":"/"}${r.url}`);for(let[i,o]of s.searchParams)Kt.test(i)&&o&&!On(o)&&e.push({location:"url",field:i,value:o,variableName:n(pr(i))})}catch{}if(r.headers){let s=Array.isArray(r.headers)?r.headers.filter(i=>i.enabled!==!1).map(i=>[i.key,i.value]):Object.entries(r.headers);for(let[i,o]of s)gp.test(i)&&o&&!On(o)&&e.push({location:"header",field:i,value:o,variableName:n(pr(i))})}if(r.query){let s=Array.isArray(r.query)?r.query.filter(i=>i.enabled!==!1).map(i=>[i.key,i.value]):Object.entries(r.query);for(let[i,o]of s)Kt.test(i)&&o&&!On(o)&&e.push({location:"query",field:i,value:o,variableName:n(pr(i))})}if(r.auth){let s=r.auth;if(s.bearerToken&&!On(s.bearerToken)&&e.push({location:"auth",field:"bearerToken",value:s.bearerToken,variableName:n("bearer_token")}),s.basicAuth&&s.basicAuth.password&&!On(s.basicAuth.password)&&e.push({location:"auth",field:"basicAuth.password",value:s.basicAuth.password,variableName:n("basic_auth_password")}),s.apikey||s.apiKey){let i=s.apikey||s.apiKey;i.value&&!On(i.value)&&e.push({location:"auth",field:"apiKey.value",value:i.value,variableName:n("api_key")})}}if(r.body){let s=typeof r.body=="object"&&"content"in r.body?r.body.content:r.body;s&&Jo(s,e,t,"")}return e}function Jo(r,e,t,n){if(r!=null){if(typeof r=="string"){let s=r.trim();if(s.startsWith("{")||s.startsWith("[")){try{Jo(JSON.parse(s),e,t,n)}catch{}return}if(s.includes("=")&&!s.includes(`
|
|
644
644
|
`)){try{let i=new URLSearchParams(s);for(let[o,a]of i)if(Kt.test(o)&&a&&!On(a)){let c=pr(o),l=2;for(;t.has(c);)c=`${pr(o)}_${l++}`;t.add(c),e.push({location:"body",field:o,path:n?`${n}.${o}`:o,value:a,variableName:c})}}catch{}return}return}if(Array.isArray(r)){r.forEach((s,i)=>Jo(s,e,t,`${n}[${i}]`));return}if(typeof r=="object")for(let[s,i]of Object.entries(r)){let o=n?`${n}.${s}`:s;if(Kt.test(s)&&i&&typeof i=="string"&&!On(i)){let a=pr(s),c=2;for(;t.has(a);)a=`${pr(s)}_${c++}`;t.add(a),e.push({location:"body",field:s,path:o,value:i,variableName:a})}else typeof i=="object"&&i!==null&&Jo(i,e,t,o)}}}function bp(r,e){let t=JSON.parse(JSON.stringify(r));for(let n of e){let s=`{{${n.variableName}}}`;switch(n.location){case"url":t.url&&(t.url=t.url.replace(new RegExp(`([?&])${py(n.field)}=[^&]*`),`$1${n.field}=${s}`));break;case"header":if(Array.isArray(t.headers)){let i=t.headers.find(o=>o.key===n.field&&o.value===n.value);i&&(i.value=s)}else t.headers&&t.headers[n.field]===n.value&&(t.headers[n.field]=s);break;case"query":if(Array.isArray(t.query)){let i=t.query.find(o=>o.key===n.field&&o.value===n.value);i&&(i.value=s)}else t.query&&t.query[n.field]===n.value&&(t.query[n.field]=s);break;case"auth":if(t.auth){if(n.field==="bearerToken")t.auth.bearerToken=s;else if(n.field==="basicAuth.password"&&t.auth.basicAuth)t.auth.basicAuth.password=s;else if(n.field==="apiKey.value"){let i=t.auth.apikey||t.auth.apiKey;i&&(i.value=s)}}break;case"body":dy(t,n.field,n.path,n.value,s);break}}return t}function dy(r,e,t,n,s){let i=typeof r.body=="object"&&r.body!==null&&"content"in r.body?r.body:null,o=i?i.content:r.body;if(o){if(typeof o=="string"){let a=o.trim();if(a.startsWith("{")||a.startsWith("[")){try{let c=JSON.parse(a);hp(c,e,t||e,n,s);let l=JSON.stringify(c,null,2);i?i.content=l:r.body=l}catch{}return}if(a.includes("=")&&!a.includes(`
|
package/dist/index.mjs
CHANGED
|
@@ -638,7 +638,7 @@ fragment TypeRef on __Type {
|
|
|
638
638
|
kind name
|
|
639
639
|
ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } }
|
|
640
640
|
}
|
|
641
|
-
`.trim(),Qs=class{constructor(e){this.httpClient=e}httpClient;schemaCache=new Map;async fetchSchema(e,t){let n={method:"POST",url:e,headers:{"Content-Type":"application/json",Accept:"application/json"
|
|
641
|
+
`.trim(),Qs=class{constructor(e){this.httpClient=e}httpClient;schemaCache=new Map;async fetchSchema(e,t){let n={method:"POST",url:e,headers:{...t||{},"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({query:Pg,operationName:"IntrospectionQuery"})},s=await this.httpClient.send(n);if(s.status<200||s.status>=300)throw new Error(`Introspection query failed with status ${s.status}: ${s.statusText}`);let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(i.errors&&i.errors.length>0){let a=i.errors.map(c=>c.message).join("; ");throw new Error(`Introspection query returned errors: ${a}`)}if(!i.data?.__schema)throw new Error("Invalid introspection response: missing __schema");let o=this.parseSchema(i.data.__schema,e);return this.schemaCache.set(e,o),o}getCachedSchema(e){return this.schemaCache.get(e)}extractOperations(e){let t=[],n=e.split(`
|
|
642
642
|
`),s=/^\s*(query|mutation|subscription)\s+(\w+)/;for(let i=0;i<n.length;i++){let o=n[i].match(s);o&&t.push({type:o[1],name:o[2],line:i+1})}return t.length===0&&e.trim().startsWith("{")&&t.push({type:"query",name:"(anonymous)",line:1}),t}clearCache(e){e?this.schemaCache.delete(e):this.schemaCache.clear()}schemaToSerializable(e){let t={};for(let[n,s]of e.types)t[n]=s;return{queryType:e.queryType,mutationType:e.mutationType,subscriptionType:e.subscriptionType,types:t,directives:e.directives,fetchedAt:e.fetchedAt,endpointUrl:e.endpointUrl}}parseSchema(e,t){let n=new Map;for(let i of e.types||[]){if(i.name.startsWith("__"))continue;let o={name:i.name,kind:i.kind,description:i.description||void 0,fields:(i.fields||[]).map(a=>this.parseField(a)),inputFields:(i.inputFields||[]).map(a=>this.parseArg(a)),enumValues:(i.enumValues||[]).map(a=>({name:a.name,description:a.description||void 0,isDeprecated:a.isDeprecated||!1,deprecationReason:a.deprecationReason||void 0})),interfaces:(i.interfaces||[]).map(a=>this.renderTypeRef(a)),possibleTypes:(i.possibleTypes||[]).map(a=>this.renderTypeRef(a))};n.set(o.name,o)}let s=(e.directives||[]).map(i=>({name:i.name,description:i.description||void 0,locations:i.locations||[],args:(i.args||[]).map(o=>this.parseArg(o))}));return{queryType:e.queryType?.name||"Query",mutationType:e.mutationType?.name||void 0,subscriptionType:e.subscriptionType?.name||void 0,types:n,directives:s,fetchedAt:Date.now(),endpointUrl:t}}parseField(e){return{name:e.name,type:this.renderTypeRef(e.type),args:(e.args||[]).map(t=>this.parseArg(t)),description:e.description||void 0,isDeprecated:e.isDeprecated||!1,deprecationReason:e.deprecationReason||void 0}}parseArg(e){return{name:e.name,type:this.renderTypeRef(e.type),defaultValue:e.defaultValue??void 0,description:e.description||void 0}}renderTypeRef(e){return e?e.kind==="NON_NULL"?`${this.renderTypeRef(e.ofType)}!`:e.kind==="LIST"?`[${this.renderTypeRef(e.ofType)}]`:e.name||"Unknown":"Unknown"}}});function St(r){let e={};for(let[t,n]of Object.entries(r))Qd.test(t)?e[t]=Array.isArray(n)?n.map(()=>Mt):Mt:e[t]=n;return e}function Jc(r=[]){return r.map(e=>e&&typeof e=="object"&&e.name&&jt.test(e.name)?{...e,value:Mt}:e)}function zc(r){try{let e=new URL(r),t=!1;for(let[n]of e.searchParams)jt.test(n)&&(e.searchParams.set(n,Mt),t=!0);return t?e.toString():r}catch{return r}}function Zs(r){if(r==null)return r;if(Array.isArray(r))return r.map(t=>Zs(t));if(typeof r!="object")return r;let e={};for(let[t,n]of Object.entries(r)){let s=jt.test(t);n===null||typeof n!="object"?e[t]=s?Mt:n:s&&Array.isArray(n)?e[t]=n.map(i=>i===null||typeof i!="object"?Mt:Zs(i)):e[t]=Zs(n)}return e}function Ig(r){try{let e=new URLSearchParams(r),t=!1;for(let[n]of e)jt.test(n)&&(e.set(n,Mt),t=!0);return t?e.toString():r}catch{return r}}function Zd(r){if(r==null)return r;if(typeof r=="object"&&!Buffer.isBuffer(r))return Zs(r);if(typeof r=="string"){let e=r.trim();if(e.startsWith("{")||e.startsWith("["))try{let t=JSON.parse(e),n=Zs(t);return JSON.stringify(n)}catch{}if(e.includes("=")&&!e.includes(`
|
|
643
643
|
`))return Ig(e)}return r}function Tg(r,e){let t=r;for(let n of e){if(n.length<Gd)continue;let s=new Set([n]);for(let i of[encodeURI,encodeURIComponent])try{s.add(i(n))}catch{}for(let i of s)i.length<Gd||!t.includes(i)||(t=t.split(i).join(Mt))}return t}function Kn(r,e){if(e.length===0)return r;if(typeof r=="string")return Tg(r,e);if(Array.isArray(r))return r.map(t=>Kn(t,e));if(r!==null&&typeof r=="object"){let t=Object.getPrototypeOf(r);if(t!==Object.prototype&&t!==null)return r;let n={};for(let[s,i]of Object.entries(r))n[s]=Kn(i,e);return n}return r}function Wc(r,e){let t=e??Mr(r.sentRequest),n={...r,sentRequest:{...r.sentRequest,url:zc(r.sentRequest.url),headers:St(r.sentRequest.headers),body:r.sentRequest.body!=null?Zd(r.sentRequest.body):r.sentRequest.body}};return Kn(n,t)}function Gc(r,e=[]){let t={...r,headers:St(r.headers),cookies:r.cookies.map(n=>n&&typeof n=="object"&&n.name&&jt.test(n.name)?{...n,value:Mt}:n)};return Kn(t,e)}function Kc(r,e=[]){let t={...r,url:zc(r.url),request:{...r.request,url:zc(r.request.url),headers:St(r.request.headers),query:St(r.request.query),params:St(r.request.params),body:r.request.body!=null?Zd(r.request.body):r.request.body},response:{headers:St(r.response.headers),body:r.response.body,time:r.response.time,size:r.response.size,cookies:r.response.cookies?Jc(r.response.cookies):r.response.cookies}};return Kn(t,e)}function cn(r){return typeof r=="string"&&Og.test(r)}function Gn(r){return r.replace(/\./g,"_").replace(/[^a-zA-Z0-9_]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").toLowerCase()}function $g(r){let e=[],t=new Set;function n(s){let i=s,o=2;for(;t.has(i);)i=`${s}_${o++}`;return t.add(i),i}if(r.url)try{let s=new URL(r.url.includes("://")?r.url:`http://placeholder${r.url.startsWith("/")?"":"/"}${r.url}`);for(let[i,o]of s.searchParams)jt.test(i)&&o&&!cn(o)&&e.push({location:"url",field:i,value:o,variableName:n(Gn(i))})}catch{}if(r.headers){let s=Array.isArray(r.headers)?r.headers.filter(i=>i.enabled!==!1).map(i=>[i.key,i.value]):Object.entries(r.headers);for(let[i,o]of s)Qd.test(i)&&o&&!cn(o)&&e.push({location:"header",field:i,value:o,variableName:n(Gn(i))})}if(r.query){let s=Array.isArray(r.query)?r.query.filter(i=>i.enabled!==!1).map(i=>[i.key,i.value]):Object.entries(r.query);for(let[i,o]of s)jt.test(i)&&o&&!cn(o)&&e.push({location:"query",field:i,value:o,variableName:n(Gn(i))})}if(r.auth){let s=r.auth;if(s.bearerToken&&!cn(s.bearerToken)&&e.push({location:"auth",field:"bearerToken",value:s.bearerToken,variableName:n("bearer_token")}),s.basicAuth&&s.basicAuth.password&&!cn(s.basicAuth.password)&&e.push({location:"auth",field:"basicAuth.password",value:s.basicAuth.password,variableName:n("basic_auth_password")}),s.apikey||s.apiKey){let i=s.apikey||s.apiKey;i.value&&!cn(i.value)&&e.push({location:"auth",field:"apiKey.value",value:i.value,variableName:n("api_key")})}}if(r.body){let s=typeof r.body=="object"&&"content"in r.body?r.body.content:r.body;s&&vo(s,e,t,"")}return e}function vo(r,e,t,n){if(r!=null){if(typeof r=="string"){let s=r.trim();if(s.startsWith("{")||s.startsWith("[")){try{vo(JSON.parse(s),e,t,n)}catch{}return}if(s.includes("=")&&!s.includes(`
|
|
644
644
|
`)){try{let i=new URLSearchParams(s);for(let[o,a]of i)if(jt.test(o)&&a&&!cn(a)){let c=Gn(o),l=2;for(;t.has(c);)c=`${Gn(o)}_${l++}`;t.add(c),e.push({location:"body",field:o,path:n?`${n}.${o}`:o,value:a,variableName:c})}}catch{}return}return}if(Array.isArray(r)){r.forEach((s,i)=>vo(s,e,t,`${n}[${i}]`));return}if(typeof r=="object")for(let[s,i]of Object.entries(r)){let o=n?`${n}.${s}`:s;if(jt.test(s)&&i&&typeof i=="string"&&!cn(i)){let a=Gn(s),c=2;for(;t.has(a);)a=`${Gn(s)}_${c++}`;t.add(a),e.push({location:"body",field:s,path:o,value:i,variableName:a})}else typeof i=="object"&&i!==null&&vo(i,e,t,o)}}}function Fg(r,e){let t=JSON.parse(JSON.stringify(r));for(let n of e){let s=`{{${n.variableName}}}`;switch(n.location){case"url":t.url&&(t.url=t.url.replace(new RegExp(`([?&])${_g(n.field)}=[^&]*`),`$1${n.field}=${s}`));break;case"header":if(Array.isArray(t.headers)){let i=t.headers.find(o=>o.key===n.field&&o.value===n.value);i&&(i.value=s)}else t.headers&&t.headers[n.field]===n.value&&(t.headers[n.field]=s);break;case"query":if(Array.isArray(t.query)){let i=t.query.find(o=>o.key===n.field&&o.value===n.value);i&&(i.value=s)}else t.query&&t.query[n.field]===n.value&&(t.query[n.field]=s);break;case"auth":if(t.auth){if(n.field==="bearerToken")t.auth.bearerToken=s;else if(n.field==="basicAuth.password"&&t.auth.basicAuth)t.auth.basicAuth.password=s;else if(n.field==="apiKey.value"){let i=t.auth.apikey||t.auth.apiKey;i&&(i.value=s)}}break;case"body":Ng(t,n.field,n.path,n.value,s);break}}return t}function Ng(r,e,t,n,s){let i=typeof r.body=="object"&&r.body!==null&&"content"in r.body?r.body:null,o=i?i.content:r.body;if(o){if(typeof o=="string"){let a=o.trim();if(a.startsWith("{")||a.startsWith("[")){try{let c=JSON.parse(a);Kd(c,e,t||e,n,s);let l=JSON.stringify(c,null,2);i?i.content=l:r.body=l}catch{}return}if(a.includes("=")&&!a.includes(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@http-forge/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Headless Postman-compatible API testing engine for Node.js, CI/CD, OpenAPI workflows, and HTTP Forge automation",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|