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

@great-detail/whatsapp

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@great-detail/whatsapp - npm Package Compare versions

Comparing version 5.5.1 to 6.0.0

dist/CloudAPI/CloudAPIInvalidParamError.d.ts

58

dist/API/AbstractAPI.d.ts

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

/// <reference types="node" />
/**

@@ -9,7 +10,30 @@ * WhatsApp NodeJS SDK.

*/
import { AccountID } from "../ID";
import APIInterface from "./APIInterface";
import type { Logger } from "winston";
export type WhatsAppAccountID = string;
export interface WhatsAppAPICreateVerifyTokenParams {
/**
* The length of the verify token.
*
* @since 5.1.0
* @default 16
*/
length?: number;
/**
* The encoding of the verify token.
*
* @since 5.1.0
* @default hex
*/
encoding?: BufferEncoding;
/**
* Random Bytes Generation.
*
* @since 5.1.0
* @default crypto.randomBytes
*/
random?: (length: number) => Buffer;
}
export interface AbstractAPIParams {
businessID: WhatsAppAccountID;
businessID?: AccountID;
logger?: Logger;

@@ -26,5 +50,31 @@ }

export default abstract class AbstractAPI implements APIInterface {
protected _businessID: WhatsAppAccountID;
/**
* Default Verify Token Length.
*
* @since 5.6.0
*/
static DEFAULT_VERIFY_TOKEN_LENGTH: number;
/**
* Default Verify Token Encoding.
*
* @since 5.6.0
*/
static DEFAULT_VERIFY_TOKEN_ENCODING: BufferEncoding;
/**
* Business ID.
*
* @since 2.0.0
*/
protected _businessID?: AccountID;
protected _logger?: Logger;
constructor({ businessID, logger }: AbstractAPIParams);
constructor({ logger, businessID }: AbstractAPIParams);
/**
* Create a new Verify Token.
* This is a random string that is used to verify that the request is coming
* from WhatsApp. This method **only** creates the value, it's usage is up to
* the implementer.
*
* @since 5.6.0
*/
static createVerifyToken({ length, encoding, random, }?: WhatsAppAPICreateVerifyTokenParams): string;
}

@@ -6,11 +6,21 @@ "use strict";

});
const crypto_1 = require("crypto");
class AbstractAPI {
constructor({
businessID,
logger
logger,
businessID
}) {
this._logger = logger;
this._businessID = businessID;
this._logger = logger;
}
static createVerifyToken({
length = this.DEFAULT_VERIFY_TOKEN_LENGTH,
encoding = this.DEFAULT_VERIFY_TOKEN_ENCODING,
random = crypto_1.randomBytes
} = {}) {
return random(length).toString(encoding);
}
}
AbstractAPI.DEFAULT_VERIFY_TOKEN_LENGTH = 16;
AbstractAPI.DEFAULT_VERIFY_TOKEN_ENCODING = "hex";
exports.default = AbstractAPI;

@@ -9,3 +9,3 @@ /**

*/
import AbstractAPI from "../../API/AbstractAPI";
import AbstractAPI, { AbstractAPIParams } from "../../API/AbstractAPI";
import EndpointType from "../../API/EndpointType";

@@ -28,2 +28,5 @@ import GraphRequest, { GraphRequestCreateParams } from "../../GraphRequest";

};
export interface CloudAPIMessageParams extends AbstractAPIParams {
businessID: string;
}
/**

@@ -36,2 +39,3 @@ * WhatsApp Message API.

export default class CloudAPIMessage extends AbstractAPI {
constructor(params: CloudAPIMessageParams);
protected getEndpoint(): EndpointType;

@@ -38,0 +42,0 @@ /**

4

dist/CloudAPI/CloudAPIMessage/index.js

@@ -15,4 +15,4 @@ "use strict";

class CloudAPIMessage extends AbstractAPI_1.default {
constructor() {
super(...arguments);
constructor(params) {
super(params);
this.audio = this._shorthandAlias(OutgoingMessageType_1.default.Audio);

@@ -19,0 +19,0 @@ this.contacts = this._shorthandAlias(OutgoingMessageType_1.default.Contacts);

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

/// <reference types="node" />
/**

@@ -11,29 +10,8 @@ * WhatsApp NodeJS SDK.

import AbstractAPI, { AbstractAPIParams } from "../API/AbstractAPI";
import CloudAPIMessage from "./CloudAPIMessage";
import CloudAPIMessage, { CloudAPIMessageParams as BaseCloudAPIMessageParams } from "./CloudAPIMessage";
import CloudAPIWebhook from "./CloudAPIWebhook";
export interface WhatsAppAPICreateVerifyTokenParams {
/**
* The length of the verify token.
*
* @since 5.1.0
* @default 16
*/
length?: number;
/**
* The encoding of the verify token.
*
* @since 5.1.0
* @default hex
*/
encoding?: BufferEncoding;
/**
* Random Bytes Generation.
*
* @since 5.1.0
* @default crypto.randomBytes
*/
random?: (length: number) => Buffer;
}
export interface WhatsAppAPIParams extends AbstractAPIParams {
}
export interface CloudAPIMessageParams extends Partial<BaseCloudAPIMessageParams> {
}
/**

@@ -46,45 +24,25 @@ * WhatsApp Cloud API SDK.

* // SDK instantiation
* const sdk = new CloudAPI("123456")
* const sdk = new CloudAPI()
*/
export default class CloudAPI extends AbstractAPI {
/**
* Default Verify Token Length.
* Webhook API.
* Receive and handle messages from WhatsApp via WebHook.
*
* @since 5.6.0
* @since 4.0.0
*/
static DEFAULT_VERIFY_TOKEN_LENGTH: number;
webhook: CloudAPIWebhook;
constructor(params: WhatsAppAPIParams);
/**
* Default Verify Token Encoding.
*
* @since 5.6.0
*/
static DEFAULT_VERIFY_TOKEN_ENCODING: BufferEncoding;
/**
* Message API.
*
* @since 5.5.0
* @since 6.0.0
* @example
* // Send a Text Message
* const message = sdk.message.text({ body: "Hello"}, { toNumber: "1234567890" });
* const message = sdk.message({ businessID: "123456" })
* .text({ body: "Hello"}, { toNumber: "1234567890" });
* const sendReceipt = await message.send();
* console.log(sendReceipt);
*/
message: CloudAPIMessage;
/**
* Webhook API.
* Receive and handle messages from WhatsApp via WebHook.
*
* @since 4.0.0
*/
webhook: CloudAPIWebhook;
constructor(params: WhatsAppAPIParams);
/**
* Create a new Verify Token.
* This is a random string that is used to verify that the request is coming
* from WhatsApp. This method **only** creates the value, it's usage is up to
* the implementer.
*
* @since 5.6.0
*/
static createVerifyToken({ length, encoding, random, }?: WhatsAppAPICreateVerifyTokenParams): string;
message({ businessID: overrideBusinessID, logger, ...params }: CloudAPIMessageParams): CloudAPIMessage;
}

@@ -12,21 +12,26 @@ "use strict";

const AbstractAPI_1 = __importDefault(require("../API/AbstractAPI"));
const CloudAPIInvalidParamError_1 = __importDefault(require("./CloudAPIInvalidParamError"));
const CloudAPIMessage_1 = __importDefault(require("./CloudAPIMessage"));
const CloudAPIWebhook_1 = __importDefault(require("./CloudAPIWebhook"));
const crypto_1 = require("crypto");
class CloudAPI extends AbstractAPI_1.default {
constructor(params) {
super(params);
this.message = new CloudAPIMessage_1.default(params);
this.webhook = new CloudAPIWebhook_1.default(params);
}
static createVerifyToken({
length = this.DEFAULT_VERIFY_TOKEN_LENGTH,
encoding = this.DEFAULT_VERIFY_TOKEN_ENCODING,
random = crypto_1.randomBytes
} = {}) {
return random(length).toString(encoding);
message({
businessID: overrideBusinessID,
logger,
...params
}) {
const businessID = overrideBusinessID ?? this._businessID;
if (!businessID) {
throw new CloudAPIInvalidParamError_1.default("Business ID is required");
}
return new CloudAPIMessage_1.default({
logger: logger ?? this._logger,
businessID,
...params
});
}
}
CloudAPI.DEFAULT_VERIFY_TOKEN_LENGTH = 16;
CloudAPI.DEFAULT_VERIFY_TOKEN_ENCODING = "hex";
exports.default = CloudAPI;

@@ -9,4 +9,3 @@ /**

*/
import { WhatsAppAccountID } from "../API/AbstractAPI";
import { MessageID } from "../ID";
import { AccountID, MessageID } from "../ID";
export declare enum EventNotificationStatusReason {

@@ -158,3 +157,3 @@ /**

*/
recipient_id: WhatsAppAccountID;
recipient_id: AccountID;
/**

@@ -161,0 +160,0 @@ * For a status to be read, it must have been delivered. In some scenarios,

{
"name": "@great-detail/whatsapp",
"version": "5.5.1",
"version": "6.0.0",
"type": "commonjs",

@@ -51,14 +51,16 @@ "description": "SDK for interfacing with WhatsApp Business Platform in Typescript or Node.js using the Cloud API, hosted by Meta.",

"scripts": {
"build": "tsc -p tsconfig.json && babel dist --out-dir dist",
"format": "npm-run-all format:*",
"format-ci": "npm-run-all format-ci:*",
"format-ci:prettier": "prettier . --check",
"format:prettier": "prettier . --write",
"lint": "npm-run-all lint:*",
"lint:cspell": "cspell .",
"lint:eslint": "eslint . --fix",
"lint:typecheck": "tsc --noEmit",
"babel": "babel dist --out-dir dist",
"build": "npm-run-all tsc babel",
"cspell": "cspell .",
"eslint": "eslint .",
"eslint:dev": "eslint . --fix",
"jest": "jest --passWithNoTests",
"lint": "npm-run-all cspell eslint typecheck prettier",
"lint:dev": "npm-run-all cspell eslint:dev typecheck prettier:dev",
"prettier": "prettier --check .",
"prettier:dev": "prettier --write .",
"start": "ts-node ./src/index.ts",
"test": "npm-run-all test:*",
"test:jest": "jest --passWithNoTests"
"test": "npm-run-all jest",
"tsc": "tsc -p tsconfig.json",
"typecheck": "tsc --noEmit"
},

@@ -65,0 +67,0 @@ "peerDependencies": {

@@ -9,9 +9,35 @@ /**

*/
import { AccountID } from "../ID";
import APIInterface from "./APIInterface";
import { randomBytes } from "crypto";
import type { Logger } from "winston";
export type WhatsAppAccountID = string;
export interface WhatsAppAPICreateVerifyTokenParams {
/**
* The length of the verify token.
*
* @since 5.1.0
* @default 16
*/
length?: number;
/**
* The encoding of the verify token.
*
* @since 5.1.0
* @default hex
*/
encoding?: BufferEncoding;
/**
* Random Bytes Generation.
*
* @since 5.1.0
* @default crypto.randomBytes
*/
random?: (length: number) => Buffer;
}
export interface AbstractAPIParams {
businessID: WhatsAppAccountID;
businessID?: AccountID;
logger?: Logger;

@@ -29,9 +55,44 @@ }

export default abstract class AbstractAPI implements APIInterface {
protected _businessID: WhatsAppAccountID;
/**
* Default Verify Token Length.
*
* @since 5.6.0
*/
public static DEFAULT_VERIFY_TOKEN_LENGTH = 16;
/**
* Default Verify Token Encoding.
*
* @since 5.6.0
*/
public static DEFAULT_VERIFY_TOKEN_ENCODING: BufferEncoding = "hex";
/**
* Business ID.
*
* @since 2.0.0
*/
protected _businessID?: AccountID;
protected _logger?: Logger;
constructor({ businessID, logger }: AbstractAPIParams) {
constructor({ logger, businessID }: AbstractAPIParams) {
this._logger = logger;
this._businessID = businessID;
this._logger = logger;
}
/**
* Create a new Verify Token.
* This is a random string that is used to verify that the request is coming
* from WhatsApp. This method **only** creates the value, it's usage is up to
* the implementer.
*
* @since 5.6.0
*/
public static createVerifyToken({
length = this.DEFAULT_VERIFY_TOKEN_LENGTH,
encoding = this.DEFAULT_VERIFY_TOKEN_ENCODING,
random = randomBytes,
}: WhatsAppAPICreateVerifyTokenParams = {}): string {
return random(length).toString(encoding);
}
}

@@ -9,3 +9,3 @@ /**

*/
import AbstractAPI from "../../API/AbstractAPI";
import AbstractAPI, { AbstractAPIParams } from "../../API/AbstractAPI";
import EndpointType from "../../API/EndpointType";

@@ -40,2 +40,6 @@ import GraphRequest, { GraphRequestCreateParams } from "../../GraphRequest";

export interface CloudAPIMessageParams extends AbstractAPIParams {
businessID: string;
}
/**

@@ -48,2 +52,6 @@ * WhatsApp Message API.

export default class CloudAPIMessage extends AbstractAPI {
constructor(params: CloudAPIMessageParams) {
super(params);
}
protected getEndpoint(): EndpointType {

@@ -50,0 +58,0 @@ return `/${this._businessID}/messages`;

@@ -10,34 +10,13 @@ /**

import AbstractAPI, { AbstractAPIParams } from "../API/AbstractAPI";
import CloudAPIMessage from "./CloudAPIMessage";
import CloudAPIInvalidParamError from "./CloudAPIInvalidParamError";
import CloudAPIMessage, {
CloudAPIMessageParams as BaseCloudAPIMessageParams,
} from "./CloudAPIMessage";
import CloudAPIWebhook from "./CloudAPIWebhook";
import { randomBytes } from "crypto";
export interface WhatsAppAPICreateVerifyTokenParams {
/**
* The length of the verify token.
*
* @since 5.1.0
* @default 16
*/
length?: number;
export interface WhatsAppAPIParams extends AbstractAPIParams {}
/**
* The encoding of the verify token.
*
* @since 5.1.0
* @default hex
*/
encoding?: BufferEncoding;
export interface CloudAPIMessageParams
extends Partial<BaseCloudAPIMessageParams> {}
/**
* Random Bytes Generation.
*
* @since 5.1.0
* @default crypto.randomBytes
*/
random?: (length: number) => Buffer;
}
export interface WhatsAppAPIParams extends AbstractAPIParams {}
/**

@@ -50,32 +29,6 @@ * WhatsApp Cloud API SDK.

* // SDK instantiation
* const sdk = new CloudAPI("123456")
* const sdk = new CloudAPI()
*/
export default class CloudAPI extends AbstractAPI {
/**
* Default Verify Token Length.
*
* @since 5.6.0
*/
public static DEFAULT_VERIFY_TOKEN_LENGTH = 16;
/**
* Default Verify Token Encoding.
*
* @since 5.6.0
*/
public static DEFAULT_VERIFY_TOKEN_ENCODING: BufferEncoding = "hex";
/**
* Message API.
*
* @since 5.5.0
* @example
* // Send a Text Message
* const message = sdk.message.text({ body: "Hello"}, { toNumber: "1234567890" });
* const sendReceipt = await message.send();
* console.log(sendReceipt);
*/
public message: CloudAPIMessage;
/**
* Webhook API.

@@ -90,3 +43,2 @@ * Receive and handle messages from WhatsApp via WebHook.

super(params);
this.message = new CloudAPIMessage(params);
this.webhook = new CloudAPIWebhook(params);

@@ -96,16 +48,28 @@ }

/**
* Create a new Verify Token.
* This is a random string that is used to verify that the request is coming
* from WhatsApp. This method **only** creates the value, it's usage is up to
* the implementer.
* Message API.
*
* @since 5.6.0
* @since 6.0.0
* @example
* // Send a Text Message
* const message = sdk.message({ businessID: "123456" })
* .text({ body: "Hello"}, { toNumber: "1234567890" });
* const sendReceipt = await message.send();
* console.log(sendReceipt);
*/
public static createVerifyToken({
length = this.DEFAULT_VERIFY_TOKEN_LENGTH,
encoding = this.DEFAULT_VERIFY_TOKEN_ENCODING,
random = randomBytes,
}: WhatsAppAPICreateVerifyTokenParams = {}): string {
return random(length).toString(encoding);
public message({
businessID: overrideBusinessID,
logger,
...params
}: CloudAPIMessageParams) {
const businessID = overrideBusinessID ?? this._businessID;
if (!businessID) {
throw new CloudAPIInvalidParamError("Business ID is required");
}
return new CloudAPIMessage({
logger: logger ?? this._logger,
businessID,
...params,
});
}
}

@@ -9,4 +9,3 @@ /**

*/
import { WhatsAppAccountID } from "../API/AbstractAPI";
import { MessageID } from "../ID";
import { AccountID, MessageID } from "../ID";

@@ -178,3 +177,3 @@ export enum EventNotificationStatusReason {

*/
recipient_id: WhatsAppAccountID;
recipient_id: AccountID;

@@ -181,0 +180,0 @@ /**

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