Messaging API Common Helpers

raw JSON →
1.0.4 verified Sat Apr 25 auth: no javascript maintenance

messaging-api-common provides shared utilities (case conversion and Axios request interceptors) for the messaging-apis family of chatbot SDKs (Messenger, LINE, Slack, Viber, Telegram). Currently at v1.0.4 (Jan 2021) with no further releases; the project has moved to v1.1.x of other packages but this common package remains unchanged. Keys differ from alternatives by offering both shallow and deep snakecase/camelcase/pascalcase conversions plus a factory for Axios interceptors. TypeScript types are included.

error TypeError: Cannot destructure property 'snakecaseKeysDeep' of 'require(...)' as it is undefined.
cause Using CJS require on a package that resolves to ESM in some bundler configurations.
fix
Use import syntax or set type: 'module' in package.json and use import.
error Error: Cannot find module 'messaging-api-common'
cause Package not installed or bundler misconfigured.
fix
Run 'npm install messaging-api-common' and ensure the package is in 'dependencies'.
gotcha snakecaseKeys and camelcaseKeys do NOT deep-convert by default. Use snakecaseKeysDeep and camelcaseKeysDeep for deep conversion.
fix Use the *Deep variants for recursive conversion.
deprecated The package is no longer actively maintained; major version 1.0.0 introduced breaking changes (camelcase keys).
fix Migrate to newer messaging-apis packages that include these utilities internally.
gotcha pascalcaseKeys does NOT handle arrays properly; it converts array elements to PascalCase strings which may not be intended.
fix Manually handle arrays or use a custom conversion function.
npm install messaging-api-common
yarn add messaging-api-common
pnpm add messaging-api-common

Demonstrates deep snakecase conversion, shallow camelcase conversion, and adding an Axios request interceptor.

import { snakecaseKeysDeep, camelcaseKeys, createRequestInterceptor } from 'messaging-api-common';
import axios from 'axios';

// Case conversion
const original = { fooBar: { barFoo: 1, bazQux: [ { nestedKey: true } ] } };
const snake = snakecaseKeysDeep(original);
console.log(snake);
// { foo_bar: { bar_foo: 1, baz_qux: [ { nested_key: true } ] } }

const camel = camelcaseKeys(snake.foo_bar, { deep: false });
console.log(camel);
// { barFoo: 1 }

// Axios interceptor
const instance = axios.create({ baseURL: 'https://api.example.com' });
instance.interceptors.request.use(createRequestInterceptor());
instance.get('/data').then(console.log);