Comparing version 1.3.3 to 2.0.0
{ | ||
"name": "fbsdk-ts", | ||
"version": "1.3.3", | ||
"version": "2.0.0", | ||
"description": "Strongly-typed promise-based client library for Facebook's Graph API using TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -53,3 +53,3 @@ # fbsdk-ts | ||
Once your app is initialized, you can read different nodes on the `Nodes` object: | ||
Once your app is initialized, you can read different nodes using the `Node` function: | ||
@@ -59,3 +59,3 @@ ```ts | ||
app.Nodes.Page('{SOME-PAGE-ID}') | ||
app.Node('Page', '{SOME-PAGE-ID}') | ||
.read('{PAGE-ACCESS-TOKEN}') | ||
@@ -67,3 +67,3 @@ .then((pageInfo) => { | ||
A node may or may not also contain `Edges`, which will return a collection of nodes related to the root node: | ||
A node may or may not also contain edges that can be accessed using the `Edge` function: | ||
@@ -73,4 +73,4 @@ ```ts | ||
app.Nodes.Page('{SOME-PAGE-ID}') | ||
.Edges.Conversations.read('{PAGE-ACCESS-TOKEN}') | ||
app.Node('Page', '{SOME-PAGE-ID}') | ||
.Edge('Conversations').read('{PAGE-ACCESS-TOKEN}') | ||
.then((conversations) => { | ||
@@ -92,3 +92,3 @@ // do stuff with conversations | ||
app.Nodes.Page('{SOME-PAGE-ID}') | ||
app.Node('Page', '{SOME-PAGE-ID}') | ||
.read('{PAGE-ACCESS-TOKEN}', ['category', 'followers_count']) | ||
@@ -107,4 +107,4 @@ .then((pageInfo) => { | ||
app.Nodes.Page('{SOME-PAGE-ID}') | ||
.Edges.Conversations.read('{PAGE-ACCESS-TOKEN}', undefined, { | ||
app.Node('Page', '{SOME-PAGE-ID}') | ||
.Edge('Conversations').read('{PAGE-ACCESS-TOKEN}', undefined, { | ||
folder: 'spam', | ||
@@ -145,3 +145,3 @@ }) | ||
`FacebookAppNoExposedNodes` is an abstract class, and the parent class of the `FacebookApp` class used in the previous examples. Both classes are virtually identical, except that `FacebookApp` exposes the nodes object on `.Nodes`, while `FacebookAppNoExposedNodes` keeps the nodes object on the projected member `_Nodes`. If you want to make a subclass that does not expose the nodes object, you can extend `FacebookAppNoExposedNodes`: | ||
`FacebookAppNoExposedNodes` is an abstract class, and the parent class of the `FacebookApp` class used in the previous examples. Both classes are virtually identical, except that `FacebookApp` exposes the nodes function on `.Node`, while `FacebookAppNoExposedNodes` keeps the nodes function on the protected member `_Node`. If you want to make a subclass that does not expose the nodes function, you can extend `FacebookAppNoExposedNodes`: | ||
@@ -152,4 +152,4 @@ ```js | ||
class FacebookPageGetter extends FacebookAppNoExposedNodes { | ||
public getPageInfo(pageId, accessToken) { | ||
return await this._Nodes.Page(pageId).read(accessToken); | ||
public async getPageInfo(pageId, accessToken) { | ||
return await this._Node('Page', pageId).read(accessToken); | ||
} | ||
@@ -296,3 +296,4 @@ } | ||
} from 'fbsdk-ts/dist/api-spec'; | ||
import Node, { Edge } from 'fbsdk-ts/dist/api-spec/node'; | ||
import Node from 'fbsdk-ts/dist/api-spec/node'; | ||
import { KnownKeys } from 'fbsdk-ts/dist/util'; | ||
@@ -318,29 +319,23 @@ interface CustomAPISpec extends APISpec { | ||
/* | ||
* Each key of the nodes object must be a function of the type: (id: string) => Node | ||
* The second parameter of the Node constructor is an implementation of the edges definition | ||
* The first parameter of the Edge constructor must the the API path to the edge | ||
* | ||
* The above requirements will by type-checked by the compiler. | ||
* The below function simply implements the node function | ||
*/ | ||
class CustomFacebookApp extends FacebookAppBase<CustomAPISpec> { | ||
protected _Nodes: APISpecNodeCollection<CustomAPISpec> = { | ||
SomeNodeName: (id: string) => | ||
new Node( | ||
this.GraphAPI, | ||
{ | ||
SomeEdge: new Edge('things', this.GraphAPI, id), | ||
}, | ||
id, | ||
), | ||
SomeEdgelessNodeName: (id: string) => new Node(this.GraphAPI, {}, id), | ||
}; | ||
protected _Node<NodeType extends KnownKeys<CustomAPISpec>>( | ||
node: NodeType, | ||
id?: string, | ||
) { | ||
return new Node<CustomAPISpec[NodeType]['node'], CustomAPISpec[NodeType]['edges']>( | ||
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: | ||
If you want to expose the nodes function as a public member variable (as the default `FacebookApp` does), you can simply add this inside your class: | ||
```ts | ||
... | ||
public Nodes = this._Nodes; | ||
public Node = this._Node; | ||
... | ||
@@ -347,0 +342,0 @@ ``` |
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
390214
347