Comparing version 1.1.0 to 1.2.0
# Changelog | ||
## [v1.2.0] - 2021-02-10 | ||
- Added Messenger Platform types | ||
- Optimized node info type keys (breaking change in certain cases) | ||
- Added delete method on nodes | ||
## [v1.1.0] - 2021-02-08 | ||
- Added create method on edges | ||
## [v1.0.1] - 2021-02-03 | ||
- Initial release (republished) |
import Node, { CRUDNodeInfo, CRUDEdgeInfoSet } from './node'; | ||
import { AdAccount, AdNetworkAnalyticsAsyncQueryResult, Album, Application, ApplicationAppEventTypes, ApplicationPermission, ApplicationPermissionStatus, AppRequest, AsyncSession, Business, ButtonAutoDetectionDeviceSelection, CanvasAppAsset, Comment, CommerceMerchantSettings, ConversionConfig, CPASAdvertiserPartnershipRecommendation, CPASCollaborationRequest, CTCertDomain, DACheck, GamesIAPProduct, InsightsQueryResult, MobileSDKGK, Photo, ProductCatalog, Profile, ProfilePictureSource, Reaction, CommerceReturn, Role, SDKMLModel, TestAccount, Conversation, Message, Destination, Doc, Event, Flight, FriendList, GroupDoc, GroupMessage, ImageCopyright, LeadGenData, UserLeadGenInfo, Link, LiveVideo, LiveVideoInputStream, LiveEncoder, User, Page, LiveVideoError, VideoPoll, MailingAddress, GroupFile, MediaFingerprint, NativeOffer, NativeOfferView, OfflineConversionDataSet, OfflineConversionDataSetUpload, CustomAudience, CustomConversion, OfflineConversionDataSetStats, CommerceMerchantTaxSettings, Video, Post, SignalsUploadProgress, GamesIAPOrder, PagePost, AssignedUser, AudioCopyright, CommerceMerchantSettingsSetupStatus, CommerceOrder, CommerceOrderTransactionDetail, CommercePayout, CustomUserSettings, InsightsResult, InstagramUser, InstantArticle, InstantArticleInsightsQueryResult, MessagingFeatureReview, MessengerProfile, PageCallToAction, PageSettings, PageThreadOwner, PageUserMessageThreadLabel, Persona, Recommendation, RTBDynamicPost, Tab, VideoCopyright, VideoCopyrightRule, VideoList, EventTour, Group, InsightBreakdown, BusinessUser, BusinessAssetGroup, Permission, URL, UserIDForApp, AdStudy, PaymentEnginePayment, PaymentSubscription, UserIDForPage, AppRequestFormerRecipient } from '../graph-api/types'; | ||
import { AdAccount, AdNetworkAnalyticsAsyncQueryResult, Album, Application, ApplicationAppEventTypes, ApplicationPermission, ApplicationPermissionStatus, AppRequest, AsyncSession, Business, ButtonAutoDetectionDeviceSelection, CanvasAppAsset, Comment, CommerceMerchantSettings, ConversionConfig, CPASAdvertiserPartnershipRecommendation, CPASCollaborationRequest, CTCertDomain, DACheck, GamesIAPProduct, InsightsQueryResult, MobileSDKGK, Photo, ProductCatalog, Profile, ProfilePictureSource, Reaction, CommerceReturn, Role, SDKMLModel, TestAccount, Conversation, Message, Destination, Doc, Event, Flight, FriendList, GroupDoc, GroupMessage, ImageCopyright, LeadGenData, UserLeadGenInfo, Link, LiveVideo, LiveVideoInputStream, LiveEncoder, User, Page, LiveVideoError, VideoPoll, MailingAddress, GroupFile, MediaFingerprint, NativeOffer, NativeOfferView, OfflineConversionDataSet, OfflineConversionDataSetUpload, CustomAudience, CustomConversion, OfflineConversionDataSetStats, CommerceMerchantTaxSettings, Video, Post, SignalsUploadProgress, GamesIAPOrder, PagePost, AssignedUser, AudioCopyright, CommerceMerchantSettingsSetupStatus, CommerceOrder, CommerceOrderTransactionDetail, CommercePayout, InsightsResult, InstagramUser, InstantArticle, InstantArticleInsightsQueryResult, MessagingFeatureReview, PageCallToAction, PageSettings, PageThreadOwner, PageUserMessageThreadLabel, Persona, Recommendation, RTBDynamicPost, Tab, VideoCopyright, VideoCopyrightRule, VideoList, EventTour, Group, InsightBreakdown, BusinessUser, BusinessAssetGroup, Permission, URL, UserIDForApp, AdStudy, PaymentEnginePayment, PaymentSubscription, UserIDForPage, AppRequestFormerRecipient } from '../graph-api/types'; | ||
import { CustomUserSettings } from '../messenger-platform/apis/custom-user-settings'; | ||
import { MessengerProfile } from '../messenger-platform/apis/messenger-profile'; | ||
import { PageMessageRequest } from '../messenger-platform/apis/send'; | ||
interface NodeGetterTypeParams { | ||
@@ -354,4 +357,5 @@ node: CRUDNodeInfo; | ||
MediaFingerprints: EdgeSpec<MediaFingerprint, 'media_fingerprints'>; | ||
Messages: CreateEdgeSpec<PageMessageRequest, 'messages'>; | ||
MessagingFeatureReview: EdgeSpec<MessagingFeatureReview, 'messaging_feature_review'>; | ||
MessengerProfile: EdgeSpec<MessengerProfile, 'messenger_profile'>; | ||
MessengerProfile: CreateEdgeSpec<MessengerProfile, 'messenger_profile'>; | ||
Nativeoffers: EdgeSpec<NativeOffer, 'nativeoffers'>; | ||
@@ -447,8 +451,12 @@ PageBackedInstagramAccounts: EdgeSpec<InstagramUser, 'page_backed_instagram_accounts'>; | ||
export declare type NodeSpec<NodeType> = { | ||
type: NodeType; | ||
read_return: NodeType; | ||
}; | ||
export declare type EdgeSpec<EdgeType, EdgePath extends string> = { | ||
type: EdgeType; | ||
read_return: EdgeType; | ||
edge: EdgePath; | ||
}; | ||
export declare type CreateEdgeSpec<EdgeType, EdgePath extends string> = { | ||
create_type: EdgeType; | ||
edge: EdgePath; | ||
}; | ||
export declare type EdgelessNodeSpec<NodeType> = { | ||
@@ -483,7 +491,7 @@ node: NodeSpec<NodeType>; | ||
declare type LikesEdge = { | ||
type: Profile; | ||
read_return: Profile; | ||
edge: 'likes'; | ||
}; | ||
declare type ReactionsEdge = { | ||
type: Profile | Reaction; | ||
read_return: Profile | Reaction; | ||
edge: 'reactions'; | ||
@@ -490,0 +498,0 @@ read_params: { |
@@ -6,10 +6,13 @@ import { FacebookAppBase } from '../index'; | ||
export interface CRUDNodeInfo { | ||
read_params?: { | ||
create_type?: any; | ||
create_params?: { | ||
[key: string]: any; | ||
}; | ||
type: any; | ||
create_params?: { | ||
create_return?: any; | ||
read_type?: never; | ||
read_params?: { | ||
[key: string]: any; | ||
}; | ||
create_return?: any; | ||
read_return?: any; | ||
update_type?: any; | ||
update_params?: { | ||
@@ -19,2 +22,3 @@ [key: string]: any; | ||
update_return?: any; | ||
delete_type?: never; | ||
delete_params?: { | ||
@@ -32,7 +36,8 @@ [key: string]: any; | ||
interface CRUDNode<ThisNode extends CRUDNodeInfo> { | ||
read: <FieldsTuple extends (keyof ThisNode['type'])[]>(access_token: string, fields?: (keyof ThisNode['type'])[], params?: Partial<ThisNode['read_params']>) => Promise<Pick<GraphAPIResponse<ThisNode['type']>, FieldsTuple[number] | 'id'>>; | ||
read: <FieldsTuple extends (keyof ThisNode['read_return'])[]>(access_token: string, fields?: (keyof ThisNode['read_return'])[], params?: Partial<ThisNode['read_params']>) => Promise<Pick<GraphAPIResponse<ThisNode['read_return']>, FieldsTuple[number] | 'id'>>; | ||
delete: (access_token: string, params?: Partial<ThisNode['delete_params']>) => Promise<ThisNode['delete_return']>; | ||
} | ||
interface CRUDEdge<ThisEdge extends CRUDEdgeInfo> { | ||
read: (...args: Parameters<CRUDNode<ThisEdge>['read']>) => Promise<EdgeResponse<DePromise<ReturnType<CRUDNode<ThisEdge>['read']>>>>; | ||
create: (access_token: string, data: Partial<ThisEdge['type']>, params?: Partial<ThisEdge['create_params']>) => Promise<ThisEdge['create_return']>; | ||
create: (access_token: string, data: Partial<ThisEdge['create_type']>, params?: Partial<ThisEdge['create_params']>) => Promise<ThisEdge['create_return']>; | ||
} | ||
@@ -48,3 +53,4 @@ export default class Node<ThisNode extends CRUDNodeInfo, Edges extends CRUDEdgeInfoSet = any> implements CRUDNode<ThisNode> { | ||
}, id?: string); | ||
read: <FieldsTuple extends (keyof ThisNode["type"])[]>(access_token: string, fields?: (keyof ThisNode['type'])[], params?: Partial<ThisNode['read_params']>) => Promise<Pick<GraphAPIResponse<ThisNode["type"]>, "id" | FieldsTuple[number]>>; | ||
read: <FieldsTuple extends (keyof ThisNode["read_return"])[]>(access_token: string, fields?: (keyof ThisNode['read_return'])[], params?: Partial<ThisNode['read_params']>) => Promise<Pick<GraphAPIResponse<ThisNode["read_return"]>, "id" | FieldsTuple[number]>>; | ||
delete: (access_token: string, params?: Partial<ThisNode['delete_params']>) => Promise<ThisNode["delete_return"]>; | ||
} | ||
@@ -56,4 +62,4 @@ export declare class Edge<ThisEdge extends CRUDEdgeInfo> implements CRUDEdge<ThisEdge> { | ||
constructor(edge: ThisEdge['edge'], GraphAPI: FacebookAppBase<APISpec>['GraphAPI'], id?: string); | ||
read: <FieldsTuple extends (keyof ThisEdge["type"])[]>(access_token: string, fields?: (keyof ThisEdge['type'])[], params?: DeepPartial<ThisEdge['read_params']>) => Promise<EdgeResponse<Pick<GraphAPIResponse<ThisEdge["type"]>, "id" | FieldsTuple[number]>>>; | ||
create: (access_token: string, data: Partial<ThisEdge['type']>, params?: Partial<ThisEdge['create_params']>) => Promise<ThisEdge["create_return"]>; | ||
read: <FieldsTuple extends (keyof ThisEdge["read_return"])[]>(access_token: string, fields?: (keyof ThisEdge['read_return'])[], params?: DeepPartial<ThisEdge['read_params']>) => Promise<EdgeResponse<Pick<GraphAPIResponse<ThisEdge["read_return"]>, "id" | FieldsTuple[number]>>>; | ||
create: (access_token: string, data: Partial<ThisEdge['create_type']>, params?: Partial<ThisEdge['create_params']>) => Promise<ThisEdge["create_return"]>; | ||
} | ||
@@ -60,0 +66,0 @@ interface EdgeResponse<NodeType> { |
@@ -27,2 +27,5 @@ "use strict"; | ||
}); | ||
this.delete = (access_token, params) => __awaiter(this, void 0, void 0, function* () { | ||
return yield this.GraphAPI.delete(this.id, Object.assign(params !== null && params !== void 0 ? params : {}, { access_token })); | ||
}); | ||
} | ||
@@ -29,0 +32,0 @@ } |
@@ -11,2 +11,3 @@ import { AxiosInstance } from 'axios'; | ||
constructor(config: FacebookAppConfig); | ||
private makeAppSecretProof; | ||
protected GraphAPI: { | ||
@@ -19,2 +20,5 @@ get: <ReturnType_1, ParamsType = any>(endpoint: string, _params?: ParamsType & { | ||
}) => Promise<ReturnType_2>; | ||
delete: <ReturnType_3, ParamsType_2 = any>(endpoint: string, _params?: ParamsType_2 & { | ||
access_token: string; | ||
}) => Promise<ReturnType_3>; | ||
}; | ||
@@ -21,0 +25,0 @@ protected abstract _Nodes: APISpecNodeCollection<API>; |
@@ -53,10 +53,11 @@ "use strict"; | ||
this.config = config; | ||
this.makeAppSecretProof = (accessToken) => crypto_1.default | ||
.createHmac('sha256', this.config.appSecret) | ||
.update(accessToken) | ||
.digest('hex') | ||
.toString(); | ||
this.GraphAPI = { | ||
get: (endpoint, _params) => __awaiter(this, void 0, void 0, function* () { | ||
const params = Object.assign(_params, { | ||
appsecret_proof: crypto_1.default | ||
.createHmac('sha256', this.config.appSecret) | ||
.update(_params.access_token) | ||
.digest('hex') | ||
.toString(), | ||
appsecret_proof: this.makeAppSecretProof(_params.access_token), | ||
}); | ||
@@ -73,7 +74,3 @@ try { | ||
const params = Object.assign(_params, { | ||
appsecret_proof: crypto_1.default | ||
.createHmac('sha256', this.config.appSecret) | ||
.update(_params.access_token) | ||
.digest('hex') | ||
.toString(), | ||
appsecret_proof: this.makeAppSecretProof(_params.access_token), | ||
}); | ||
@@ -88,2 +85,14 @@ try { | ||
}), | ||
delete: (endpoint, _params) => __awaiter(this, void 0, void 0, function* () { | ||
const params = Object.assign(_params, { | ||
appsecret_proof: this.makeAppSecretProof(_params.access_token), | ||
}); | ||
try { | ||
const response = ((yield this.graphAPIAxiosInstance.delete(endpoint, { params })).data); | ||
return response; | ||
} | ||
catch (e) { | ||
handleFacebookError(e); | ||
} | ||
}), | ||
}; | ||
@@ -234,2 +243,3 @@ } | ||
Locations: new node_1.Edge('locations', this.GraphAPI, id), | ||
Messages: new node_1.Edge('messages', this.GraphAPI, id), | ||
MediaFingerprints: new node_1.Edge('media_fingerprints', this.GraphAPI, id), | ||
@@ -275,3 +285,3 @@ MessagingFeatureReview: new node_1.Edge('messaging_feature_review', this.GraphAPI, id), | ||
User: (id) => new node_1.default(this.GraphAPI, { | ||
"Payment.subscriptions": new node_1.Edge('payment.subscriptions', this.GraphAPI, id), | ||
'Payment.subscriptions': new node_1.Edge('payment.subscriptions', this.GraphAPI, id), | ||
Accounts: new node_1.Edge('accounts', this.GraphAPI, id), | ||
@@ -306,3 +316,3 @@ AdStudies: new node_1.Edge('ad_studies', this.GraphAPI, id), | ||
Posts: new node_1.Edge('posts', this.GraphAPI, id), | ||
Videos: new node_1.Edge('videos', this.GraphAPI, id) | ||
Videos: new node_1.Edge('videos', this.GraphAPI, id), | ||
}, id), | ||
@@ -309,0 +319,0 @@ Video: (id) => new node_1.default(this.GraphAPI, {}, id), |
{ | ||
"name": "fbsdk-ts", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Strongly-typed promise-based client library for Facebook's Graph API using TypeScript", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"prune": "rm dist/util.js dist/graph-api/types.js dist/api-spec/index.js", | ||
"prune": "node bin/prune.js", | ||
"all": "npm run clean && npm run build && npm run prune" | ||
@@ -36,4 +36,6 @@ }, | ||
"!dist/graph-api/types.js", | ||
"!dist/api-spec/index.js" | ||
"!dist/messenger-platform/apis/custom-user-settings.js", | ||
"!dist/messenger-platform/apis/messenger-profile.js", | ||
"!dist/messenger-platform/apis/send.js" | ||
] | ||
} |
@@ -200,7 +200,7 @@ # fbsdk-ts | ||
node: { | ||
type: SomeNode; // the type that defines the shape of the node | ||
read_return: SomeNode; // the type that defines the shape of the node | ||
}; | ||
edges: { | ||
SomeEdge: { | ||
type: EdgeResult; // The type that defines the shape of the nodes returned by the edge | ||
read_return: EdgeResult; // The type that defines the shape of the nodes returned by the edge | ||
edge: 'things'; // The API path for the edge | ||
@@ -207,0 +207,0 @@ }; |
Sorry, the diff of this file is too big to display
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
374621
15
11585