-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'juliemturner-version-4' into version-4
- Loading branch information
Showing
27 changed files
with
1,037 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# @pnp/graph/analytics | ||
|
||
The ability to get analytics for OneDrive and SharePoint drive items, SharePoint sites, and SharePoint list items. | ||
|
||
## IInvitations | ||
|
||
[![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) | ||
|
||
## Get Drive Item Analytics | ||
|
||
Using analytics() you get the Item Analytics for a Drive Item | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/users"; | ||
import "@pnp/graph/drive"; | ||
import "@pnp/graph/analytics"; | ||
import { IAnalyticsOptions } from "@pnp/graph/analytics"; | ||
|
||
const graph = graphfi(...); | ||
|
||
// Defaults to lastSevenDays | ||
const analytics = await graph.users.getById("[email protected]").drives.getById("{drive id}").items.getById("{item id}").analytics()(); | ||
|
||
const analytics = await graph.me.drives.getById("{drive id}").items.getById("{item id}").analytics()(); | ||
|
||
// Get analytics for all time | ||
const analyticOptions: IAnalyticsOptions = { | ||
timeRange: "allTime" | ||
}; | ||
|
||
const analyticsAllTime = await graph.me.drives.getById("{drive id}").items.getById("{item id}").analytics(analyticOptions)(); | ||
``` | ||
|
||
## Get Site Analytics | ||
|
||
Using analytics() you can get the analytics for a SharePoint site | ||
|
||
```TypeScript | ||
import { graphfi } from "@pnp/graph"; | ||
import "@pnp/graph/sites"; | ||
import "@pnp/graph/analytics"; | ||
import { IAnalyticsOptions } from "@pnp/graph/analytics"; | ||
|
||
const graph = graphfi(...); | ||
|
||
const site = this.pnp.graph.sites.getById(this.pnp.settings.graph.id); | ||
|
||
// Defaults to lastSevenDays | ||
const analytics = await site.analytics(); | ||
|
||
// Get analytics for all time | ||
const analyticOptions: IAnalyticsOptions = { | ||
timeRange: "allTime" | ||
}; | ||
|
||
const analyticsAllTime = await site.analytics(analyticOptions); | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { _DriveItem } from "../files/types.js"; | ||
import { analytics, IAnalyticsOptions } from "./types.js"; | ||
import { ItemAnalytics as IItemAnalytics } from "@microsoft/microsoft-graph-types"; | ||
|
||
declare module "../files/types" { | ||
interface _DriveItem { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
|
||
interface DriveItem { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
} | ||
|
||
_DriveItem.prototype.analytics = analytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "./driveItems.js"; | ||
import "./listItems.js"; | ||
import "./sites.js"; | ||
|
||
export { | ||
IAnalyticsOptions, | ||
} from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { _ListItem } from "../list-item/types.js"; | ||
import { IAnalyticsOptions, analytics } from "./types.js"; | ||
import { ItemAnalytics as IItemAnalytics } from "@microsoft/microsoft-graph-types"; | ||
|
||
declare module "../list-item/types" { | ||
interface _ListItem { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
|
||
interface ListItem { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
} | ||
|
||
_ListItem.prototype.analytics = analytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { _Site } from "../sites/types.js"; | ||
import { IAnalyticsOptions, analytics } from "./types.js"; | ||
import { ItemAnalytics as IItemAnalytics } from "@microsoft/microsoft-graph-types"; | ||
|
||
|
||
declare module "../sites/types" { | ||
interface _Site { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
|
||
interface ISite { | ||
analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics>; | ||
} | ||
} | ||
|
||
_Site.prototype.analytics = analytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ItemAnalytics as IItemAnalytics } from "@microsoft/microsoft-graph-types"; | ||
import { GraphQueryable, graphGet } from "../graphqueryable.js"; | ||
|
||
export interface IAnalyticsOptions { | ||
timeRange: "allTime" | "lastSevenDays"; | ||
} | ||
|
||
export function analytics(analyticsOptions?: IAnalyticsOptions): Promise<IItemAnalytics> { | ||
const query = `analytics/${analyticsOptions ? analyticsOptions.timeRange : "lastSevenDays"}`; | ||
return graphGet(GraphQueryable(this, query)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import "./list.js"; | ||
|
||
export { | ||
ListItems, | ||
IListItems, | ||
ListItem, | ||
IListItem, | ||
IListItemAddResult, | ||
} from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { addProp } from "@pnp/queryable"; | ||
import { _List } from "../lists/types.js"; | ||
import { ListItems, IListItems } from "./types.js"; | ||
|
||
declare module "../lists/types" { | ||
interface _List { | ||
readonly items: IListItems; | ||
} | ||
interface IList { | ||
readonly items: IListItems; | ||
} | ||
} | ||
|
||
addProp(_List, "items", ListItems); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ListItem as IListItemEntity, ListItemVersion as IListItemVersion } from "@microsoft/microsoft-graph-types"; | ||
import { _GraphCollection, graphInvokableFactory, _GraphInstance, IGraphCollection, GraphCollection, graphPost } from "../graphqueryable.js"; | ||
import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; | ||
import { body } from "@pnp/queryable"; | ||
|
||
/** | ||
* Represents a list item entity | ||
*/ | ||
@deleteable() | ||
@updateable() | ||
export class _ListItem extends _GraphInstance<IListItemEntity> { | ||
/** | ||
* Method for retrieving the versions of a list item. | ||
* @returns IListItemVersion | ||
*/ | ||
public get versions(): IGraphCollection<IListItemVersion> { | ||
return <any>GraphCollection(this, "versions"); | ||
} | ||
} | ||
export interface IListItem extends _ListItem, IDeleteable, IUpdateable { } | ||
export const ListItem = graphInvokableFactory<IListItem>(_ListItem); | ||
|
||
/** | ||
* Describes a collection of list item objects | ||
* | ||
*/ | ||
@defaultPath("items") | ||
@getById(ListItem) | ||
export class _ListItems extends _GraphCollection<IListItemEntity[]>{ | ||
/** | ||
* Create a new list item as specified in the request body. | ||
* | ||
* @param listItem a JSON representation of a List object. | ||
*/ | ||
public async add(listItem: IListItemEntity): Promise<IListItemAddResult> { | ||
const data = await graphPost(this, body(listItem)); | ||
|
||
return { | ||
data, | ||
list: (<any>this).getById(data.id), | ||
}; | ||
} | ||
} | ||
|
||
export interface IListItems extends _ListItems, IGetById<IListItem> { } | ||
export const ListItems = graphInvokableFactory<IListItems>(_ListItems); | ||
|
||
/** | ||
* IListAddResult | ||
*/ | ||
export interface IListItemAddResult { | ||
list: IListItem; | ||
data: IListItemEntity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.