@great-detail/whatsapp
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -11,3 +11,3 @@ /** | ||
import GraphResponse from "../GraphResponse"; | ||
export interface GraphRequestProps extends RequestInit { | ||
export interface GraphRequestCreateParams extends RequestInit { | ||
endpoint?: EndpointType; | ||
@@ -26,7 +26,16 @@ version?: string; | ||
export default class GraphRequest<T = unknown> extends Request { | ||
endpoint: EndpointType; | ||
version: string; | ||
baseUrl: string; | ||
constructor({ endpoint, version, baseUrl, ...requestInit }: GraphRequestProps); | ||
/** | ||
* Default base URL for the Facebook Graph API. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
static DEFAULT_GRAPH_API_BASE_URL: string; | ||
/** | ||
* Default version for the Facebook Graph API. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
static DEFAULT_GRAPH_VERSION: string; | ||
static create<C = unknown>({ endpoint, version, baseUrl, ...requestInit }: GraphRequestCreateParams): GraphRequest<C>; | ||
/** | ||
* Send Request using Fetch. | ||
@@ -33,0 +42,0 @@ * |
@@ -12,16 +12,10 @@ "use strict"; | ||
const GraphResponse_1 = __importDefault(require("../GraphResponse")); | ||
const constants_1 = require("../constants"); | ||
class GraphRequest extends Request { | ||
constructor({ | ||
static create({ | ||
endpoint = "/", | ||
version = constants_1.DEFAULT_GRAPH_VERSION, | ||
baseUrl = constants_1.DEFAULT_GRAPH_API_BASE_URL, | ||
version = this.DEFAULT_GRAPH_VERSION, | ||
baseUrl = this.DEFAULT_GRAPH_API_BASE_URL, | ||
...requestInit | ||
}) { | ||
super(new URL([version ? "/" : "", version, endpoint].join(""), baseUrl), { | ||
...requestInit | ||
}); | ||
this.endpoint = endpoint; | ||
this.version = version; | ||
this.baseUrl = baseUrl; | ||
return new GraphRequest(new URL([version ? "/" : "", version, endpoint].join(""), baseUrl), requestInit); | ||
} | ||
@@ -41,2 +35,4 @@ async send() { | ||
} | ||
GraphRequest.DEFAULT_GRAPH_API_BASE_URL = "https://graph.facebook.com"; | ||
GraphRequest.DEFAULT_GRAPH_VERSION = "v18.0"; | ||
exports.default = GraphRequest; |
@@ -10,3 +10,3 @@ /** | ||
import AbstractAPI from "../API/AbstractAPI"; | ||
import GraphRequest, { GraphRequestProps } from "../GraphRequest"; | ||
import GraphRequest, { GraphRequestCreateParams } from "../GraphRequest"; | ||
import ComponentTypesEnum from "../Message/ComponentTypesEnum"; | ||
@@ -30,3 +30,3 @@ import { ContactsObjectMessageType } from "../Message/ContactsMessageType"; | ||
replyMessageId?: string; | ||
requestProps?: GraphRequestProps; | ||
requestProps?: GraphRequestCreateParams; | ||
}; | ||
@@ -47,3 +47,3 @@ /** | ||
*/ | ||
createStatus(payload: StatusObjectMessageType, requestProps?: GraphRequestProps): GraphRequest<MessageResponseType>; | ||
createStatus(payload: StatusObjectMessageType, requestProps?: GraphRequestCreateParams): GraphRequest<MessageResponseType>; | ||
/** | ||
@@ -50,0 +50,0 @@ * Create Message. |
@@ -36,3 +36,3 @@ "use strict"; | ||
}; | ||
return new GraphRequest_1.default({ | ||
return GraphRequest_1.default.create({ | ||
...requestProps, | ||
@@ -63,3 +63,3 @@ endpoint: this.getEndpoint(), | ||
}; | ||
return new GraphRequest_1.default({ | ||
return GraphRequest_1.default.create({ | ||
...requestProps, | ||
@@ -66,0 +66,0 @@ endpoint: this.getEndpoint(), |
@@ -12,6 +12,6 @@ "use strict"; | ||
const AbstractAPI_1 = __importDefault(require("../API/AbstractAPI")); | ||
const GraphRequest_1 = __importDefault(require("../GraphRequest")); | ||
const MessageAPI_1 = __importDefault(require("../MessageAPI")); | ||
const constants_1 = require("../constants"); | ||
class WhatsAppAPI extends AbstractAPI_1.default { | ||
constructor(businessId, version = constants_1.DEFAULT_GRAPH_VERSION, baseUrl = constants_1.DEFAULT_GRAPH_API_BASE_URL, logger) { | ||
constructor(businessId, version = GraphRequest_1.default.DEFAULT_GRAPH_VERSION, baseUrl = GraphRequest_1.default.DEFAULT_GRAPH_API_BASE_URL, logger) { | ||
super(businessId, undefined, logger); | ||
@@ -18,0 +18,0 @@ this.version = version; |
{ | ||
"name": "@great-detail/whatsapp", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"license": "SEE LICENSE IN LICENSE FILE", | ||
@@ -47,3 +47,3 @@ "description": "SDK for interfacing with WhatsApp Business Platform in Typescript or Node.js using the Cloud API, hosted by Meta.", | ||
"lint:eslint": "eslint . --fix", | ||
"lint:cspell": "cspell \"{README.md,.github/*.md,docs/**/*.md}\"", | ||
"lint:cspell": "cspell .", | ||
"lint:typecheck": "tsc --noEmit", | ||
@@ -50,0 +50,0 @@ "test": "npm-run-all test:*", |
@@ -11,8 +11,4 @@ /** | ||
import GraphResponse from "../GraphResponse"; | ||
import { | ||
DEFAULT_GRAPH_API_BASE_URL, | ||
DEFAULT_GRAPH_VERSION, | ||
} from "../constants"; | ||
export interface GraphRequestProps extends RequestInit { | ||
export interface GraphRequestCreateParams extends RequestInit { | ||
endpoint?: EndpointType; | ||
@@ -32,19 +28,26 @@ version?: string; | ||
export default class GraphRequest<T = unknown> extends Request { | ||
public endpoint: EndpointType; | ||
public version: string; | ||
public baseUrl: string; | ||
/** | ||
* Default base URL for the Facebook Graph API. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public static DEFAULT_GRAPH_API_BASE_URL = "https://graph.facebook.com"; | ||
constructor({ | ||
/** | ||
* Default version for the Facebook Graph API. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public static DEFAULT_GRAPH_VERSION = "v18.0"; | ||
public static create<C = unknown>({ | ||
endpoint = "/", | ||
version = DEFAULT_GRAPH_VERSION, | ||
baseUrl = DEFAULT_GRAPH_API_BASE_URL, | ||
version = this.DEFAULT_GRAPH_VERSION, | ||
baseUrl = this.DEFAULT_GRAPH_API_BASE_URL, | ||
...requestInit | ||
}: GraphRequestProps) { | ||
super(new URL([version ? "/" : "", version, endpoint].join(""), baseUrl), { | ||
...requestInit, | ||
}); | ||
this.endpoint = endpoint; | ||
this.version = version; | ||
this.baseUrl = baseUrl; | ||
}: GraphRequestCreateParams) { | ||
return new GraphRequest<C>( | ||
new URL([version ? "/" : "", version, endpoint].join(""), baseUrl), | ||
requestInit, | ||
); | ||
} | ||
@@ -51,0 +54,0 @@ |
@@ -10,3 +10,3 @@ /** | ||
import AbstractAPI from "../API/AbstractAPI"; | ||
import GraphRequest, { GraphRequestProps } from "../GraphRequest"; | ||
import GraphRequest, { GraphRequestCreateParams } from "../GraphRequest"; | ||
import ComponentTypesEnum from "../Message/ComponentTypesEnum"; | ||
@@ -45,3 +45,3 @@ import { ContactsObjectMessageType } from "../Message/ContactsMessageType"; | ||
replyMessageId?: string; | ||
requestProps?: GraphRequestProps; | ||
requestProps?: GraphRequestCreateParams; | ||
}; | ||
@@ -72,3 +72,3 @@ | ||
payload: StatusObjectMessageType, | ||
requestProps: GraphRequestProps = {}, | ||
requestProps: GraphRequestCreateParams = {}, | ||
) { | ||
@@ -80,3 +80,3 @@ const body: StatusMessageType = { | ||
return new GraphRequest<MessageResponseType>({ | ||
return GraphRequest.create<MessageResponseType>({ | ||
...requestProps, | ||
@@ -117,3 +117,3 @@ endpoint: this.getEndpoint(), | ||
return new GraphRequest<MessageResponseType>({ | ||
return GraphRequest.create<MessageResponseType>({ | ||
...requestProps, | ||
@@ -120,0 +120,0 @@ endpoint: this.getEndpoint(), |
@@ -10,7 +10,4 @@ /** | ||
import AbstractAPI from "../API/AbstractAPI"; | ||
import GraphRequest from "../GraphRequest"; | ||
import MessageAPI from "../MessageAPI"; | ||
import { | ||
DEFAULT_GRAPH_API_BASE_URL, | ||
DEFAULT_GRAPH_VERSION, | ||
} from "../constants"; | ||
import type { Logger } from "winston"; | ||
@@ -29,4 +26,4 @@ | ||
businessId: string, | ||
public version: string = DEFAULT_GRAPH_VERSION, | ||
public baseUrl: string = DEFAULT_GRAPH_API_BASE_URL, | ||
public version: string = GraphRequest.DEFAULT_GRAPH_VERSION, | ||
public baseUrl: string = GraphRequest.DEFAULT_GRAPH_API_BASE_URL, | ||
logger?: Logger, | ||
@@ -33,0 +30,0 @@ ) { |
Sorry, the diff of this file is not supported yet
139748
108
3237