@great-detail/whatsapp
Advanced tools
Comparing version 6.4.8 to 6.5.0
@@ -1,2 +0,2 @@ | ||
import t from"../../API/AbstractAPI.js";import s from"../../GraphRequest/index.js";import e from"../../Message/MessageType/OutgoingMessageType.js";export default class i extends t{constructor(t){super(t),this.audio=this._shorthandAlias(e.Audio),this.contacts=this._shorthandAlias(e.Contacts),this.document=this._shorthandAlias(e.Document),this.image=this._shorthandAlias(e.Image),this.interactive=this._shorthandAlias(e.Interactive),this.location=this._shorthandAlias(e.Location),this.sticker=this._shorthandAlias(e.Sticker),this.template=this._shorthandAlias(e.Template),this.text=this._shorthandAlias(e.Text),this.video=this._shorthandAlias(e.Video)}getEndpoint(){return`/${this._businessID}/messages`}createStatus(t,e={}){let i={messaging_product:"whatsapp",...t};return s.create({logger:this._logger,...e,endpoint:this.getEndpoint(),method:"POST",body:JSON.stringify(i),headers:{...e.headers,"Content-Type":"application/json"}})}createMessage(t,e,{toNumber:i,replyMessageId:a,requestProps:h={}}){let n={messaging_product:"whatsapp",recipient_type:"individual",to:i,type:t,[t]:e};return a&&(n.context={message_id:a}),s.create({logger:this._logger,...h,endpoint:this.getEndpoint(),method:"POST",body:JSON.stringify(n),headers:{...h.headers,"Content-Type":"application/json"}})}_shorthandAlias(t){return(function(s,e){return this.createMessage(t,s,e)}).bind(this)}} | ||
import t from"../../API/AbstractAPI.js";import s from"../../GraphRequest/index.js";import e from"../../Message/MessageType/OutgoingMessageType.js";export default class i extends t{constructor(t){super(t),this.audio=this._shorthandAlias(e.Audio),this.contacts=this._shorthandAlias(e.Contacts),this.document=this._shorthandAlias(e.Document),this.image=this._shorthandAlias(e.Image),this.interactive=this._shorthandAlias(e.Interactive),this.location=this._shorthandAlias(e.Location),this.sticker=this._shorthandAlias(e.Sticker),this.template=this._shorthandAlias(e.Template),this.text=this._shorthandAlias(e.Text),this.video=this._shorthandAlias(e.Video)}getEndpoint(){return`/${this._businessID}/messages`}createStatus(t,e={}){let i={messaging_product:"whatsapp",...t};return new s(this.getEndpoint(),{logger:this._logger,...e,method:"POST",body:JSON.stringify(i),headers:{...e.headers,"Content-Type":"application/json"}})}createMessage(t,e,{toNumber:i,replyMessageId:a,requestProps:h={}}){let n={messaging_product:"whatsapp",recipient_type:"individual",to:i,type:t,[t]:e};return a&&(n.context={message_id:a}),new s(this.getEndpoint(),{logger:this._logger,...h,method:"POST",body:JSON.stringify(n),headers:{...h.headers,"Content-Type":"application/json"}})}_shorthandAlias(t){return(function(s,e){return this.createMessage(t,s,e)}).bind(this)}} | ||
//# sourceMappingURL=index.js.map |
@@ -12,4 +12,3 @@ /** | ||
import { Logger } from "winston"; | ||
export interface GraphRequestCreateParams extends RequestInit { | ||
endpoint?: EndpointType; | ||
export interface GraphRequestParameters extends RequestInit { | ||
version?: string; | ||
@@ -19,2 +18,4 @@ baseUrl?: string; | ||
} | ||
export interface GraphRequestCreateParams extends GraphRequestParameters { | ||
} | ||
export interface GraphRequestSendParams extends RequestInit { | ||
@@ -52,9 +53,21 @@ /** | ||
/** | ||
* Create a new Graph API Request. | ||
* Graph API version. | ||
* | ||
* @since 4.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
* @since 6.5.0 | ||
*/ | ||
static create<C = unknown>({ endpoint, version, baseUrl, logger, ...requestInit }: GraphRequestCreateParams): GraphRequest<C>; | ||
readonly version: string; | ||
/** | ||
* Graph API endpoint. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
readonly endpoint: string; | ||
/** | ||
* Graph API base URL. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
readonly baseUrl: string; | ||
constructor(endpoint: EndpointType, { logger, version, baseUrl, ...requestInit }?: GraphRequestParameters); | ||
/** | ||
* Send Request using Fetch. | ||
@@ -61,0 +74,0 @@ * |
@@ -1,2 +0,2 @@ | ||
import t from"../GraphResponse/index.js";export default class e extends Request{static{this.DEFAULT_GRAPH_API_BASE_URL="https://graph.facebook.com"}static{this.DEFAULT_GRAPH_VERSION="v18.0"}static create({endpoint:t="/",version:s=this.DEFAULT_GRAPH_VERSION,baseUrl:i=this.DEFAULT_GRAPH_API_BASE_URL,logger:n,...a}){let h=new URL([s?"/":"",s,t].join(""),i);return n?.http(`${h.toString()} ${JSON.stringify(a)}`),new e(h,a)}async send({fetch:e=fetch,...s}={}){return await e(this,s).then(({body:e,...s})=>new t(e,s))}} | ||
import t from"../GraphResponse/index.js";export default class s extends Request{static{this.DEFAULT_GRAPH_API_BASE_URL="https://graph.facebook.com"}static{this.DEFAULT_GRAPH_VERSION="v18.0"}constructor(t,{logger:e,version:i=s.DEFAULT_GRAPH_VERSION,baseUrl:n=s.DEFAULT_GRAPH_API_BASE_URL,...r}={}){let h=new URL([i?"/":"",i,t].join(""),n);super(h,r),this.version=i,this.endpoint=t,this.baseUrl=n,e?.http(`${h.toString()} ${JSON.stringify(r)}`)}async send({fetch:s=fetch,...e}={}){return await s(this,e).then(({body:s,...e})=>new t(s,{request:this,...e}))}} | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,6 @@ /** | ||
*/ | ||
import GraphRequest from "../GraphRequest/index.js"; | ||
export interface GraphResponseParameters<T = unknown> extends ResponseInit { | ||
request?: GraphRequest<T>; | ||
} | ||
/** | ||
@@ -17,3 +21,13 @@ * Graph API Response. | ||
export default class GraphResponse<T = unknown> extends Response { | ||
readonly request?: GraphRequest<T>; | ||
constructor(bodyInit: ReadableStream | null, { request, ...parameters }?: GraphResponseParameters<T>); | ||
/** | ||
* Whether the Request was upgraded in API versions. | ||
* If the incoming version cannot be determined then undefined will be | ||
* returned. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
get isUpgraded(): boolean | undefined; | ||
json(): Promise<T>; | ||
} |
@@ -1,2 +0,2 @@ | ||
export default class e extends Response{json(){return super.json()}} | ||
export default class e extends Response{constructor(e,{request:s,...r}={}){super(e,r),this.request=s}get isUpgraded(){let e=this.request?.version,s=this.headers.get("facebook-api-version");if(s&&e)return s===e}json(){return super.json()}} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@great-detail/whatsapp", | ||
"version": "6.4.8", | ||
"version": "6.5.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "SDK for interfacing with WhatsApp Business Platform in Typescript or Node.js using the Cloud API, hosted by Meta.", |
@@ -75,6 +75,5 @@ /** | ||
return GraphRequest.create<CloudOutgoingMessageResponse>({ | ||
return new GraphRequest<CloudOutgoingMessageResponse>(this.getEndpoint(), { | ||
logger: this._logger, | ||
...requestProps, | ||
endpoint: this.getEndpoint(), | ||
method: "POST", | ||
@@ -110,6 +109,5 @@ body: JSON.stringify(body), | ||
return GraphRequest.create<CloudOutgoingMessageResponse>({ | ||
return new GraphRequest<CloudOutgoingMessageResponse>(this.getEndpoint(), { | ||
logger: this._logger, | ||
...requestProps, | ||
endpoint: this.getEndpoint(), | ||
method: "POST", | ||
@@ -116,0 +114,0 @@ body: JSON.stringify(body), |
@@ -13,4 +13,3 @@ /** | ||
export interface GraphRequestCreateParams extends RequestInit { | ||
endpoint?: EndpointType; | ||
export interface GraphRequestParameters extends RequestInit { | ||
version?: string; | ||
@@ -21,2 +20,4 @@ baseUrl?: string; | ||
export interface GraphRequestCreateParams extends GraphRequestParameters {} | ||
export interface GraphRequestSendParams extends RequestInit { | ||
@@ -57,14 +58,31 @@ /** | ||
/** | ||
* Create a new Graph API Request. | ||
* Graph API version. | ||
* | ||
* @since 4.0.0 | ||
* @author Dom Webber <dom.webber@hotmail.com> | ||
* @since 6.5.0 | ||
*/ | ||
public static create<C = unknown>({ | ||
endpoint = "/", | ||
version = this.DEFAULT_GRAPH_VERSION, | ||
baseUrl = this.DEFAULT_GRAPH_API_BASE_URL, | ||
logger, | ||
...requestInit | ||
}: GraphRequestCreateParams) { | ||
public readonly version: string; | ||
/** | ||
* Graph API endpoint. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
public readonly endpoint: string; | ||
/** | ||
* Graph API base URL. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
public readonly baseUrl: string; | ||
public constructor( | ||
endpoint: EndpointType, | ||
{ | ||
logger, | ||
version = GraphRequest.DEFAULT_GRAPH_VERSION, | ||
baseUrl = GraphRequest.DEFAULT_GRAPH_API_BASE_URL, | ||
...requestInit | ||
}: GraphRequestParameters = {}, | ||
) { | ||
const url = new URL( | ||
@@ -74,5 +92,9 @@ [version ? "/" : "", version, endpoint].join(""), | ||
); | ||
super(url, requestInit); | ||
this.version = version; | ||
this.endpoint = endpoint; | ||
this.baseUrl = baseUrl; | ||
logger?.http(`${url.toString()} ${JSON.stringify(requestInit)}`); | ||
return new GraphRequest<C>(url, requestInit); | ||
} | ||
@@ -91,5 +113,6 @@ | ||
return await fetchAlternative(this, requestInit).then( | ||
({ body, ...responseInit }) => new GraphResponse(body, responseInit), | ||
({ body, ...responseInit }) => | ||
new GraphResponse(body, { request: this, ...responseInit }), | ||
); | ||
} | ||
} |
@@ -9,3 +9,8 @@ /** | ||
*/ | ||
import GraphRequest from "../GraphRequest/index.js"; | ||
export interface GraphResponseParameters<T = unknown> extends ResponseInit { | ||
request?: GraphRequest<T>; | ||
} | ||
/** | ||
@@ -18,2 +23,29 @@ * Graph API Response. | ||
export default class GraphResponse<T = unknown> extends Response { | ||
public readonly request?: GraphRequest<T>; | ||
constructor( | ||
bodyInit: ReadableStream | null, | ||
{ request, ...parameters }: GraphResponseParameters<T> = {}, | ||
) { | ||
super(bodyInit, parameters); | ||
this.request = request; | ||
} | ||
/** | ||
* Whether the Request was upgraded in API versions. | ||
* If the incoming version cannot be determined then undefined will be | ||
* returned. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
public get isUpgraded(): boolean | undefined { | ||
const outgoingVersion = this.request?.version; | ||
const incomingVersion = this.headers.get("facebook-api-version"); | ||
if (!incomingVersion || !outgoingVersion) { | ||
return undefined; | ||
} | ||
return incomingVersion === outgoingVersion; | ||
} | ||
public override json(): Promise<T> { | ||
@@ -20,0 +52,0 @@ return super.json(); |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284198
399
6626