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

messaging-api-common

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messaging-api-common - npm Package Compare versions

Comparing version 1.0.0-beta.0 to 1.0.0-beta.1

dist/case.d.ts

22

dist/index.d.ts

@@ -1,3 +0,4 @@

declare function onRequest(request: {
method: string;
import { AxiosRequestConfig, Method } from 'axios';
declare function defaultOnRequest(request: {
method?: Method;
url: string;

@@ -7,9 +8,14 @@ headers: Record<string, any>;

}): void;
declare function snakecaseKeysDeep(obj: Record<string, any>): {
[key: string]: unknown;
declare type RequestPayload = {
method?: Method;
url: string;
headers: Record<string, any>;
body: any;
};
declare function camelcaseKeysDeep(obj: Record<string, any>): {
[key: string]: unknown;
};
export { onRequest, snakecaseKeysDeep, camelcaseKeysDeep };
export declare type OnRequestFunction = (request: RequestPayload) => void;
declare function createRequestInterceptor({ onRequest, }?: {
onRequest?: OnRequestFunction;
}): (config: AxiosRequestConfig) => AxiosRequestConfig;
export * from './case';
export { defaultOnRequest as onRequest, createRequestInterceptor };
//# sourceMappingURL=index.d.ts.map
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,8 +9,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
const camel_case_1 = __importDefault(require("camel-case"));
const debug_1 = __importDefault(require("debug"));
const map_obj_1 = __importDefault(require("map-obj"));
const snake_case_1 = __importDefault(require("snake-case"));
const debugRequest = debug_1.default('messaging-api-common:request');
function onRequest(request) {
const omit_1 = __importDefault(require("lodash/omit"));
const url_join_1 = __importDefault(require("url-join"));
const debugRequest = debug_1.default('messaging-api:request');
function defaultOnRequest(request) {
if (request.body) {

@@ -23,23 +25,24 @@ debugRequest('Outgoing request body:');

}
exports.onRequest = onRequest;
function isLastCharNumber(key) {
return /^\d$/.test(key[key.length - 1]);
exports.onRequest = defaultOnRequest;
function createRequestInterceptor({ onRequest = defaultOnRequest, } = {}) {
return (config) => {
onRequest({
method: config.method,
url: url_join_1.default(config.baseURL || '', config.url || '/'),
headers: Object.assign(Object.assign(Object.assign({}, config.headers.common), (config.method ? config.headers[config.method] : {})), omit_1.default(config.headers, [
'common',
'get',
'post',
'put',
'patch',
'delete',
'head',
])),
body: config.data,
});
return config;
};
}
function splitLastChar(key) {
return `${key.slice(0, key.length - 1)}_${key.slice(key.length - 1, key.length)}`;
}
function snakecaseKeysDeep(obj) {
return map_obj_1.default(obj, (key, val) => [
snake_case_1.default(isLastCharNumber(key) ? splitLastChar(key) : key),
val,
], { deep: true });
}
exports.snakecaseKeysDeep = snakecaseKeysDeep;
function camelcaseKeysDeep(obj) {
return map_obj_1.default(obj, (key, val) => [
camel_case_1.default(isLastCharNumber(key) ? splitLastChar(key) : key),
val,
], { deep: true });
}
exports.camelcaseKeysDeep = camelcaseKeysDeep;
exports.createRequestInterceptor = createRequestInterceptor;
__export(require("./case"));
//# sourceMappingURL=index.js.map

@@ -9,10 +9,14 @@ {

},
"version": "1.0.0-beta.0",
"version": "1.0.0-beta.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"axios": "^0.19.0",
"camel-case": "^3.0.0",
"debug": "^4.1.1",
"lodash": "^4.17.15",
"map-obj": "^4.1.0",
"snake-case": "^2.1.0"
"pascal-case": "^2.0.1",
"snake-case": "^2.1.0",
"url-join": "^4.0.1"
},

@@ -27,3 +31,3 @@ "keywords": [

},
"gitHead": "96eaeb0fc0b1bf8799d17dd93aa4c59f1eeeb0f3"
"gitHead": "c92c8cdb79d62893a7c07f5208a5234f7bfc00cb"
}

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

import camelCase from 'camel-case';
import debug from 'debug';
import mapObject from 'map-obj';
import snakeCase from 'snake-case';
import omit from 'lodash/omit';
import urlJoin from 'url-join';
import { AxiosRequestConfig, Method } from 'axios';
const debugRequest = debug('messaging-api-common:request');
const debugRequest = debug('messaging-api:request');
function onRequest(request: {
method: string;
function defaultOnRequest(request: {
method?: Method;
url: string;

@@ -24,35 +24,41 @@ headers: Record<string, any>;

function isLastCharNumber(key: string) {
return /^\d$/.test(key[key.length - 1]);
}
type RequestPayload = {
method?: Method;
url: string;
headers: Record<string, any>;
body: any;
};
function splitLastChar(key: string) {
return `${key.slice(0, key.length - 1)}_${key.slice(
key.length - 1,
key.length
)}`;
}
export type OnRequestFunction = (request: RequestPayload) => void;
function snakecaseKeysDeep(obj: Record<string, any>) {
return mapObject(
obj,
(key, val) => [
snakeCase(isLastCharNumber(key) ? splitLastChar(key) : key),
val,
],
{ deep: true }
);
}
function createRequestInterceptor({
onRequest = defaultOnRequest,
}: { onRequest?: OnRequestFunction } = {}) {
return (config: AxiosRequestConfig) => {
onRequest({
method: config.method,
url: urlJoin(config.baseURL || '', config.url || '/'),
headers: {
...config.headers.common,
...(config.method ? config.headers[config.method] : {}),
...omit(config.headers, [
'common',
'get',
'post',
'put',
'patch',
'delete',
'head',
]),
},
function camelcaseKeysDeep(obj: Record<string, any>) {
return mapObject(
obj,
(key, val) => [
camelCase(isLastCharNumber(key) ? splitLastChar(key) : key),
val,
],
{ deep: true }
);
body: config.data,
});
return config;
};
}
export { onRequest, snakecaseKeysDeep, camelcaseKeysDeep };
export * from './case';
export { defaultOnRequest as onRequest, createRequestInterceptor };

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