Comparing version 1.3.2 to 1.3.3
@@ -400,33 +400,33 @@ import Node, { CRUDNodeInfo, CRUDEdgeInfoSet } from './node'; | ||
edges: { | ||
Albums: EdgeSpec<Album, 'albums'>; | ||
AppRequestFormerRecipients: EdgeSpec<AppRequestFormerRecipient, 'apprequestformerrecipients'>; | ||
AppRequests: EdgeSpec<AppRequest, 'apprequests'>; | ||
BusinessUsers: EdgeSpec<BusinessUser, 'business_users'>; | ||
Businesses: EdgeSpec<Business, 'businesses'>; | ||
Accounts: EdgeSpec<Page, 'accounts'>; | ||
AdStudies: EdgeSpec<AdStudy, 'ad_studies'>; | ||
Adaccounts: EdgeSpec<AdAccount, 'adaccounts'>; | ||
AssignedAdAccounts: EdgeSpec<AdAccount, 'assigned_ad_accounts'>; | ||
AssignedBusinessAssetGroups: EdgeSpec<BusinessAssetGroup, 'assigned_business_asset_groups'>; | ||
AssignedPages: EdgeSpec<Page, 'assigned_pages'>; | ||
AssignedProductCatalogs: EdgeSpec<ProductCatalog, 'assigned_product_catalogs'>; | ||
Events: EdgeSpec<Event, 'events'>; | ||
Feed: EdgeSpec<Post, 'feed'>; | ||
Friends: EdgeSpec<User, 'friends'>; | ||
Groups: EdgeSpec<Group, 'groups'>; | ||
IdsForApps: EdgeSpec<UserIDForApp, 'ids_for_apps'>; | ||
IdsForBusiness: EdgeSpec<UserIDForApp, 'ids_for_business'>; | ||
IdsForPages: EdgeSpec<UserIDForPage, 'ids_for_pages'>; | ||
Likes: EdgeSpec<Page, 'likes'>; | ||
LiveEncoders: EdgeSpec<LiveEncoder, 'live_encoders'>; | ||
LiveVideos: EdgeSpec<LiveVideo, 'live_videos'>; | ||
Music: EdgeSpec<Page, 'music'>; | ||
'Albums': EdgeSpec<Album, 'albums'>; | ||
'AppRequestFormerRecipients': EdgeSpec<AppRequestFormerRecipient, 'apprequestformerrecipients'>; | ||
'AppRequests': EdgeSpec<AppRequest, 'apprequests'>; | ||
'BusinessUsers': EdgeSpec<BusinessUser, 'business_users'>; | ||
'Businesses': EdgeSpec<Business, 'businesses'>; | ||
'Accounts': EdgeSpec<Page, 'accounts'>; | ||
'AdStudies': EdgeSpec<AdStudy, 'ad_studies'>; | ||
'Adaccounts': EdgeSpec<AdAccount, 'adaccounts'>; | ||
'AssignedAdAccounts': EdgeSpec<AdAccount, 'assigned_ad_accounts'>; | ||
'AssignedBusinessAssetGroups': EdgeSpec<BusinessAssetGroup, 'assigned_business_asset_groups'>; | ||
'AssignedPages': EdgeSpec<Page, 'assigned_pages'>; | ||
'AssignedProductCatalogs': EdgeSpec<ProductCatalog, 'assigned_product_catalogs'>; | ||
'Events': EdgeSpec<Event, 'events'>; | ||
'Feed': EdgeSpec<Post, 'feed'>; | ||
'Friends': EdgeSpec<User, 'friends'>; | ||
'Groups': EdgeSpec<Group, 'groups'>; | ||
'IdsForApps': EdgeSpec<UserIDForApp, 'ids_for_apps'>; | ||
'IdsForBusiness': EdgeSpec<UserIDForApp, 'ids_for_business'>; | ||
'IdsForPages': EdgeSpec<UserIDForPage, 'ids_for_pages'>; | ||
'Likes': EdgeSpec<Page, 'likes'>; | ||
'LiveEncoders': EdgeSpec<LiveEncoder, 'live_encoders'>; | ||
'LiveVideos': EdgeSpec<LiveVideo, 'live_videos'>; | ||
'Music': EdgeSpec<Page, 'music'>; | ||
'Payment.subscriptions': EdgeSpec<PaymentSubscription, 'payment.subscriptions'>; | ||
PaymentTransactions: EdgeSpec<PaymentEnginePayment, 'payment_transactions'>; | ||
Permissions: EdgeSpec<Permission, 'permissions'>; | ||
PersonalAdAccounts: EdgeSpec<AdAccount, 'personal_ad_accounts'>; | ||
Photos: EdgeSpec<Photo, 'photos'>; | ||
Picture: EdgeSpec<ProfilePictureSource, 'picture'>; | ||
Posts: EdgeSpec<Post, 'posts'>; | ||
Videos: EdgeSpec<Video, 'videos'>; | ||
'PaymentTransactions': EdgeSpec<PaymentEnginePayment, 'payment_transactions'>; | ||
'Permissions': EdgeSpec<Permission, 'permissions'>; | ||
'PersonalAdAccounts': EdgeSpec<AdAccount, 'personal_ad_accounts'>; | ||
'Photos': EdgeSpec<Photo, 'photos'>; | ||
'Picture': EdgeSpec<ProfilePictureSource, 'picture'>; | ||
'Posts': EdgeSpec<Post, 'posts'>; | ||
'Videos': EdgeSpec<Video, 'videos'>; | ||
}; | ||
@@ -433,0 +433,0 @@ }; |
@@ -34,3 +34,3 @@ import { FacebookAppBase } from '../index'; | ||
interface CRUDNode<ThisNode extends CRUDNodeInfo> { | ||
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'>>; | ||
read: <FieldsTuple extends (keyof ThisNode['read_return'])[]>(access_token: string, fields?: FieldsTuple, 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']>; | ||
@@ -51,3 +51,3 @@ } | ||
}, id?: string); | ||
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]>>; | ||
read: <FieldsTuple extends (keyof ThisNode["read_return"])[]>(access_token: string, fields?: FieldsTuple, 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"]>; | ||
@@ -54,0 +54,0 @@ } |
@@ -64,3 +64,4 @@ "use strict"; | ||
try { | ||
const response = ((yield this.graphAPIAxiosInstance.get(endpoint, { params })).data); | ||
const response = ((yield this.graphAPIAxiosInstance.get(endpoint, { params })) | ||
.data); | ||
return response; | ||
@@ -77,3 +78,5 @@ } | ||
try { | ||
const response = ((yield this.graphAPIAxiosInstance.post(endpoint, data, { params })).data); | ||
const response = (yield this.graphAPIAxiosInstance.post(endpoint, data, { | ||
params, | ||
})).data; | ||
return response; | ||
@@ -90,3 +93,5 @@ } | ||
try { | ||
const response = ((yield this.graphAPIAxiosInstance.delete(endpoint, { params })).data); | ||
const response = (yield this.graphAPIAxiosInstance.delete(endpoint, { | ||
params, | ||
})).data; | ||
return response; | ||
@@ -285,32 +290,32 @@ } | ||
'Payment.subscriptions': new node_1.Edge('payment.subscriptions', this.GraphAPI, id), | ||
Accounts: new node_1.Edge('accounts', this.GraphAPI, id), | ||
AdStudies: new node_1.Edge('ad_studies', this.GraphAPI, id), | ||
Adaccounts: new node_1.Edge('adaccounts', this.GraphAPI, id), | ||
Albums: new node_1.Edge('albums', this.GraphAPI, id), | ||
AppRequestFormerRecipients: new node_1.Edge('apprequestformerrecipients', this.GraphAPI, id), | ||
AppRequests: new node_1.Edge('apprequests', this.GraphAPI, id), | ||
AssignedAdAccounts: new node_1.Edge('assigned_ad_accounts', this.GraphAPI, id), | ||
AssignedBusinessAssetGroups: new node_1.Edge('assigned_business_asset_groups', this.GraphAPI, id), | ||
AssignedPages: new node_1.Edge('assigned_pages', this.GraphAPI, id), | ||
AssignedProductCatalogs: new node_1.Edge('assigned_product_catalogs', this.GraphAPI, id), | ||
BusinessUsers: new node_1.Edge('business_users', this.GraphAPI, id), | ||
Businesses: new node_1.Edge('businesses', this.GraphAPI, id), | ||
Events: new node_1.Edge('events', this.GraphAPI, id), | ||
Feed: new node_1.Edge('feed', this.GraphAPI, id), | ||
Friends: new node_1.Edge('friends', this.GraphAPI, id), | ||
Groups: new node_1.Edge('groups', this.GraphAPI, id), | ||
IdsForApps: new node_1.Edge('ids_for_apps', this.GraphAPI, id), | ||
IdsForBusiness: new node_1.Edge('ids_for_business', this.GraphAPI, id), | ||
IdsForPages: new node_1.Edge('ids_for_pages', this.GraphAPI, id), | ||
Likes: new node_1.Edge('likes', this.GraphAPI, id), | ||
LiveEncoders: new node_1.Edge('live_encoders', this.GraphAPI, id), | ||
LiveVideos: new node_1.Edge('live_videos', this.GraphAPI, id), | ||
Music: new node_1.Edge('music', this.GraphAPI, id), | ||
PaymentTransactions: new node_1.Edge('payment_transactions', this.GraphAPI, id), | ||
Permissions: new node_1.Edge('permissions', this.GraphAPI, id), | ||
PersonalAdAccounts: new node_1.Edge('personal_ad_accounts', this.GraphAPI, id), | ||
Photos: new node_1.Edge('photos', this.GraphAPI, id), | ||
Picture: new node_1.Edge('picture', this.GraphAPI, id), | ||
Posts: new node_1.Edge('posts', this.GraphAPI, id), | ||
Videos: new node_1.Edge('videos', this.GraphAPI, id), | ||
'Accounts': new node_1.Edge('accounts', this.GraphAPI, id), | ||
'AdStudies': new node_1.Edge('ad_studies', this.GraphAPI, id), | ||
'Adaccounts': new node_1.Edge('adaccounts', this.GraphAPI, id), | ||
'Albums': new node_1.Edge('albums', this.GraphAPI, id), | ||
'AppRequestFormerRecipients': new node_1.Edge('apprequestformerrecipients', this.GraphAPI, id), | ||
'AppRequests': new node_1.Edge('apprequests', this.GraphAPI, id), | ||
'AssignedAdAccounts': new node_1.Edge('assigned_ad_accounts', this.GraphAPI, id), | ||
'AssignedBusinessAssetGroups': new node_1.Edge('assigned_business_asset_groups', this.GraphAPI, id), | ||
'AssignedPages': new node_1.Edge('assigned_pages', this.GraphAPI, id), | ||
'AssignedProductCatalogs': new node_1.Edge('assigned_product_catalogs', this.GraphAPI, id), | ||
'BusinessUsers': new node_1.Edge('business_users', this.GraphAPI, id), | ||
'Businesses': new node_1.Edge('businesses', this.GraphAPI, id), | ||
'Events': new node_1.Edge('events', this.GraphAPI, id), | ||
'Feed': new node_1.Edge('feed', this.GraphAPI, id), | ||
'Friends': new node_1.Edge('friends', this.GraphAPI, id), | ||
'Groups': new node_1.Edge('groups', this.GraphAPI, id), | ||
'IdsForApps': new node_1.Edge('ids_for_apps', this.GraphAPI, id), | ||
'IdsForBusiness': new node_1.Edge('ids_for_business', this.GraphAPI, id), | ||
'IdsForPages': new node_1.Edge('ids_for_pages', this.GraphAPI, id), | ||
'Likes': new node_1.Edge('likes', this.GraphAPI, id), | ||
'LiveEncoders': new node_1.Edge('live_encoders', this.GraphAPI, id), | ||
'LiveVideos': new node_1.Edge('live_videos', this.GraphAPI, id), | ||
'Music': new node_1.Edge('music', this.GraphAPI, id), | ||
'PaymentTransactions': new node_1.Edge('payment_transactions', this.GraphAPI, id), | ||
'Permissions': new node_1.Edge('permissions', this.GraphAPI, id), | ||
'PersonalAdAccounts': new node_1.Edge('personal_ad_accounts', this.GraphAPI, id), | ||
'Photos': new node_1.Edge('photos', this.GraphAPI, id), | ||
'Picture': new node_1.Edge('picture', this.GraphAPI, id), | ||
'Posts': new node_1.Edge('posts', this.GraphAPI, id), | ||
'Videos': new node_1.Edge('videos', this.GraphAPI, id), | ||
}, id), | ||
@@ -321,3 +326,5 @@ Video: (id) => new node_1.default(this.GraphAPI, {}, id), | ||
}; | ||
this.graphAPIAxiosInstance = axios_1.default.create({ baseURL: `https://graph.facebook.com/v9.0` }); | ||
this.graphAPIAxiosInstance = axios_1.default.create({ | ||
baseURL: `https://graph.facebook.com/v9.0`, | ||
}); | ||
} | ||
@@ -324,0 +331,0 @@ } |
@@ -97,4 +97,4 @@ import { XOR } from '../../util'; | ||
*/ | ||
call_to_actions: (XOR<[PostbackButton, URLButton]>)[]; | ||
call_to_actions: XOR<[PostbackButton, URLButton]>[]; | ||
} | ||
export {}; |
@@ -103,3 +103,7 @@ import { XOR } from '../../util'; | ||
} | ||
declare type QuickReply = XOR<[QuickReplyText, QuickReplyTextWithImage, QuickReplyUserInfo]>; | ||
declare type QuickReply = XOR<[ | ||
QuickReplyText, | ||
QuickReplyTextWithImage, | ||
QuickReplyUserInfo | ||
]>; | ||
interface PageMessageWithText extends PageMessageBase { | ||
@@ -148,4 +152,16 @@ /** | ||
} | ||
declare type PageMessageAttachment = XOR<[PageMessageFileAttachment, PageMessageTemplateAttachment]>; | ||
export declare type MessageTemplate = XOR<[GenericTemplate, ButtonTemplate, MediaTemplate, ReceiptTemplate, AirlineBoardingPassTemplate, AirlineCheckInTemplate, AirlineItineraryTemplate, AirlineFlightUpdateTemplate]>; | ||
declare type PageMessageAttachment = XOR<[ | ||
PageMessageFileAttachment, | ||
PageMessageTemplateAttachment | ||
]>; | ||
export declare type MessageTemplate = XOR<[ | ||
GenericTemplate, | ||
ButtonTemplate, | ||
MediaTemplate, | ||
ReceiptTemplate, | ||
AirlineBoardingPassTemplate, | ||
AirlineCheckInTemplate, | ||
AirlineItineraryTemplate, | ||
AirlineFlightUpdateTemplate | ||
]>; | ||
declare type AirlineTemplateType = `airline_${'boardingpass' | 'checkin' | 'itinerary' | 'update'}`; | ||
@@ -505,3 +521,6 @@ interface MessageTemplateBase { | ||
} | ||
declare type AirlineBoardingPassTemplateBoardingPass = XOR<[AirlineBoardingPassTemplateBoardingPassWithQRCode, AirlineBoardingPassTemplateBoardingPassWithBarCode]>; | ||
declare type AirlineBoardingPassTemplateBoardingPass = XOR<[ | ||
AirlineBoardingPassTemplateBoardingPassWithQRCode, | ||
AirlineBoardingPassTemplateBoardingPassWithBarCode | ||
]>; | ||
interface AirlineCheckInTemplate extends AirlineMessageTemplateBase { | ||
@@ -732,3 +751,9 @@ template_type: 'airline_checkin'; | ||
} | ||
declare type MessageButton = XOR<[URLButton, PostbackButton, CallButton, LoginButton, LogoutButton]>; | ||
declare type MessageButton = XOR<[ | ||
URLButton, | ||
PostbackButton, | ||
CallButton, | ||
LoginButton, | ||
LogoutButton | ||
]>; | ||
export {}; |
{ | ||
"name": "fbsdk-ts", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Strongly-typed promise-based client library for Facebook's Graph API using TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -6,7 +6,8 @@ # fbsdk-ts | ||
# Where do I start? | ||
- For most use cases: [How to use](#how-to-use) | ||
- For more experienced developers: [How to extend / subclass](#how-to-extend--subclass) | ||
- For advanced developers and contributors: [How to add nodes / edges](#how-to-add-nodes--edges) | ||
- For those who want the node types: [How to access the node types](#how-to-access-the-node-types) | ||
- For most use cases: [How to use](#how-to-use) | ||
- For more experienced developers: [How to extend / subclass](#how-to-extend--subclass) | ||
- For advanced developers and contributors: [How to add nodes / edges](#how-to-add-nodes--edges) | ||
- For those who want the node types: [How to access the node types](#how-to-access-the-node-types) | ||
# How to use: | ||
@@ -49,5 +50,4 @@ | ||
***NOTE:** Never use your app secret directly in your code, as this is a security risk! Environment variables are recommended for storing your app secret.* | ||
**\*NOTE:** Never use your app secret directly in your code, as this is a security risk! Environment variables are recommended for storing your app secret.\* | ||
## Step 3: Reading Nodes and Edges | ||
@@ -81,5 +81,4 @@ | ||
***NOTE:** As with your app secret, never use your access tokens directly in your code. Environment variables are again recommended for storing your access tokens.* | ||
**\*NOTE:** As with your app secret, never use your access tokens directly in your code. Environment variables are again recommended for storing your access tokens.\* | ||
## Step 4: Selecting Fields | ||
@@ -89,3 +88,3 @@ | ||
```js | ||
```ts | ||
// Get the category and follower count of a page | ||
@@ -100,10 +99,2 @@ | ||
If you are using TypeScript, you can limit the fields of the result type by duplicating your fields array as a type parameter on the `.read` method: | ||
```ts | ||
... | ||
.read<['category', 'followers_count']>('{PAGE-ACCESS-TOKEN}', ['category', 'followers_count']) | ||
... | ||
``` | ||
## Step 5: Using Read Parameters | ||
@@ -117,3 +108,5 @@ | ||
app.Nodes.Page('{SOME-PAGE-ID}') | ||
.Edges.Conversations.read('{PAGE-ACCESS-TOKEN}', undefined, { folder: 'spam' }) | ||
.Edges.Conversations.read('{PAGE-ACCESS-TOKEN}', undefined, { | ||
folder: 'spam', | ||
}) | ||
.then((spamConversations) => { | ||
@@ -219,2 +212,3 @@ // do stuff with spam conversations | ||
These definitions can be further simplified by helper types: | ||
```ts | ||
@@ -228,3 +222,3 @@ import { FacebookAppBase } from 'fbsdk-ts'; | ||
edges: { | ||
SomeEdge: EdgeSpec<EdgeResult,'things'>; | ||
SomeEdge: EdgeSpec<EdgeResult, 'things'>; | ||
}; | ||
@@ -234,6 +228,13 @@ }; | ||
``` | ||
If a node doesn't have any edges, its definition can be further shortened with another helper type: | ||
```ts | ||
import { FacebookAppBase } from 'fbsdk-ts'; | ||
import { APISpec, NodeSpec, EdgeSpec, EdgelessNodeSpec } from 'fbsdk-ts/dist/api-spec'; | ||
import { | ||
APISpec, | ||
NodeSpec, | ||
EdgeSpec, | ||
EdgelessNodeSpec, | ||
} from 'fbsdk-ts/dist/api-spec'; | ||
@@ -244,3 +245,3 @@ interface CustomAPISpec extends APISpec { | ||
edges: { | ||
SomeEdge: EdgeSpec<EdgeResult,'things'>; | ||
SomeEdge: EdgeSpec<EdgeResult, 'things'>; | ||
}; | ||
@@ -251,6 +252,13 @@ }; | ||
``` | ||
Nodes and edges can have read parameters defined like so: | ||
```ts | ||
import { FacebookAppBase } from 'fbsdk-ts'; | ||
import { APISpec, NodeSpec, EdgeSpec, EdgelessNodeSpec } from 'fbsdk-ts/dist/api-spec'; | ||
import { | ||
APISpec, | ||
NodeSpec, | ||
EdgeSpec, | ||
EdgelessNodeSpec, | ||
} from 'fbsdk-ts/dist/api-spec'; | ||
@@ -265,3 +273,3 @@ interface CustomAPISpec extends APISpec { | ||
edges: { | ||
SomeEdge: EdgeSpec<EdgeResult,'things'> & { | ||
SomeEdge: EdgeSpec<EdgeResult, 'things'> & { | ||
read_params: { | ||
@@ -276,8 +284,18 @@ include_specific_kind: boolean; | ||
``` | ||
For more specific code examples, see [the v9 APISpec definition](/src/api-spec/index.ts). If you want to contribute more nodes/edges to this project, please add onto the type definition in that file. | ||
## Step 3: Implementing the definition | ||
Import the `Node` and `Edge` classes from `fbsdk-ts/dist/api-spec/node`. Your custom APISpec definition can now be implemented in a subclass of `FacebookAppBase`: | ||
Import the `Node` and `Edge` classes from `fbsdk-ts/dist/api-spec/node`. Your custom APISpec definition can now be implemented in a subclass of `FacebookAppBase`: | ||
```ts | ||
import { FacebookAppBase } from 'fbsdk-ts'; | ||
import { APISpec, NodeSpec, EdgeSpec, EdgelessNodeSpec, APISpecNodeCollection } from 'fbsdk-ts/dist/api-spec'; | ||
import { | ||
APISpec, | ||
NodeSpec, | ||
EdgeSpec, | ||
EdgelessNodeSpec, | ||
APISpecNodeCollection, | ||
} from 'fbsdk-ts/dist/api-spec'; | ||
import Node, { Edge } from 'fbsdk-ts/dist/api-spec/node'; | ||
@@ -293,3 +311,3 @@ | ||
edges: { | ||
SomeEdge: EdgeSpec<EdgeResult,'things'> & { | ||
SomeEdge: EdgeSpec<EdgeResult, 'things'> & { | ||
read_params: { | ||
@@ -320,3 +338,3 @@ include_specific_kind: boolean; | ||
}, | ||
id | ||
id, | ||
), | ||
@@ -329,2 +347,3 @@ SomeEdgelessNodeName: (id: string) => new Node(this.GraphAPI, {}, id), | ||
If you want to expose the nodes as a public member variable (as the default `FacebookApp` does), you can simply add this inside your class: | ||
```ts | ||
@@ -335,2 +354,3 @@ ... | ||
``` | ||
This class can also be used as described in [how to extend / subclass](#how-to-extend--subclass). | ||
@@ -342,3 +362,2 @@ | ||
The nodes can be imported from `fbsdk-ts/dist/graph-api/types` like so: | ||
@@ -350,2 +369,2 @@ | ||
Please check the [source file](/src/graph-api/types.ts) for the names of all the currently available types. | ||
Please check the [source file](/src/graph-api/types.ts) for the names of all the currently available types. |
Sorry, the diff of this file is too big to display
12125
352
390541
17