Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@scalar/helpers

Package Overview
Dependencies
Maintainers
8
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scalar/helpers - npm Package Compare versions

Comparing version
0.5.0
to
0.5.1
+6
-0
CHANGELOG.md
# @scalar/helpers
## 0.5.1
### Patch Changes
- [#8911](https://github.com/scalar/scalar/pull/8911): feat: switch from Request to RequestPayload to support body with GET
## 0.5.0

@@ -4,0 +10,0 @@

+10
-6

@@ -1,8 +0,12 @@

import type { HttpMethod } from './http-methods.js';
/** HTTP Methods which can have a body */
declare const BODY_METHODS: ["post", "put", "patch", "delete"];
type BodyMethod = (typeof BODY_METHODS)[number];
/** Makes a check to see if this method CAN have a body */
export declare const canMethodHaveBody: (method: HttpMethod) => method is BodyMethod;
export {};
export declare const BODY_METHODS: Set<string>;
/**
* Makes a check to see if this method CAN have a body.
*
* When running inside Electron, all requests are also allowed to have a body because the underlying
* undici implementation does not reject it, which matches the behavior users expect from desktop API clients.
*/
export declare const canMethodHaveBody: (method: string, skipElectron?: boolean) => boolean;
/*** We must purge body from requests that cannot accept it, skips the electron check */
export declare const buildSafeBodyRequest: (url: string, init: RequestInit) => Request;
//# sourceMappingURL=can-method-have-body.d.ts.map

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

{"version":3,"file":"can-method-have-body.d.ts","sourceRoot":"","sources":["../../src/http/can-method-have-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,yCAAyC;AACzC,QAAA,MAAM,YAAY,oCAAqE,CAAA;AACvF,KAAK,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/C,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,GAAI,QAAQ,UAAU,KAAG,MAAM,IAAI,UACN,CAAA"}
{"version":3,"file":"can-method-have-body.d.ts","sourceRoot":"","sources":["../../src/http/can-method-have-body.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,eAAO,MAAM,YAAY,aAA8C,CAAA;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,eAAc,OAAe,KAAG,OASjF,CAAA;AAED,wFAAwF;AACxF,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,EAAE,MAAM,WAAW,YAI/D,CAAA"}

@@ -0,4 +1,22 @@

import { isElectron } from '../general/is-electron.js';
/** HTTP Methods which can have a body */
const BODY_METHODS = ['post', 'put', 'patch', 'delete'];
/** Makes a check to see if this method CAN have a body */
export const canMethodHaveBody = (method) => BODY_METHODS.includes(method.toLowerCase());
export const BODY_METHODS = new Set(['post', 'put', 'patch', 'delete']);
/**
* Makes a check to see if this method CAN have a body.
*
* When running inside Electron, all requests are also allowed to have a body because the underlying
* undici implementation does not reject it, which matches the behavior users expect from desktop API clients.
*/
export const canMethodHaveBody = (method, skipElectron = false) => {
const normalized = method.toLowerCase();
// For electron we allow any method to have a body
if (isElectron() && !skipElectron) {
return true;
}
return BODY_METHODS.has(normalized);
};
/*** We must purge body from requests that cannot accept it, skips the electron check */
export const buildSafeBodyRequest = (url, init) => new Request(url, {
...init,
body: canMethodHaveBody(init.method ?? 'GET', true) ? init.body : null,
});

@@ -6,3 +6,3 @@ /** All OpenAPI HTTP methods */

/** Set of all http methods we support */
export declare const httpMethods: Readonly<Set<"delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace">>;
export declare const httpMethods: Readonly<Set<"post" | "put" | "patch" | "delete" | "get" | "head" | "options" | "trace">>;
//# sourceMappingURL=http-methods.d.ts.map

@@ -17,3 +17,3 @@ {

],
"version": "0.5.0",
"version": "0.5.1",
"engines": {

@@ -20,0 +20,0 @@ "node": ">=22"