Skip to content

Commit

Permalink
Merge branch 'juliemturner-version-4' into version-4
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemturner committed Aug 28, 2023
2 parents d8aaaae + 9d267cd commit cdf8bda
Show file tree
Hide file tree
Showing 27 changed files with 1,037 additions and 578 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
"typescript.validate.enable": true,
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.tabSize": 4,
"cSpell.words": [
"queryables"
],
}
58 changes: 58 additions & 0 deletions docs/graph/analytics.md
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);
```
1,153 changes: 631 additions & 522 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"version": "4.0.0-alpha0",
"description": "A JavaScript library for SharePoint & Graph development.",
"devDependencies": {
"@azure/identity": "3.2.4",
"@azure/identity": "3.3.0",
"@azure/msal-node": "1.18.0",
"@microsoft/microsoft-graph-types": "2.35.0",
"@microsoft/microsoft-graph-types": "2.38.0",
"@pnp/buildsystem": "3.1.0",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
Expand All @@ -16,25 +16,25 @@
"@types/gulp": "4.0.13",
"@types/mocha": "10.0.1",
"@types/node": "16.11.7",
"@types/webpack": "5.28.1",
"@types/webpack": "5.28.2",
"@types/yargs": "17.0.24",
"@typescript-eslint/eslint-plugin": "5.59.9",
"@typescript-eslint/parser": "5.59.9",
"chai": "4.3.7",
"@typescript-eslint/eslint-plugin": "6.4.1",
"@typescript-eslint/parser": "6.4.1",
"chai": "4.3.8",
"chai-as-promised": "7.1.1",
"del-cli": "5.0.0",
"eslint": "8.45.0",
"del-cli": "5.0.1",
"eslint": "8.48.0",
"findup-sync": "5.0.0",
"mocha": "10.2.0",
"msal": "1.4.18",
"node-fetch": "3.3.1",
"node-fetch": "3.3.2",
"prettyjson": "1.2.5",
"string-replace-loader": "3.1.0",
"tslib": "2.6.0",
"tslib": "2.6.2",
"typescript": "4.5.5",
"webpack": "5.88.2",
"webpack-cli": "5.1.4",
"webpack-dev-server": "4.15.0",
"webpack-dev-server": "4.15.1",
"yargs": "17.7.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/azidjsclient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@pnp/core": "0.0.0-PLACEHOLDER",
"@pnp/queryable": "0.0.0-PLACEHOLDER",
"@azure/identity": "3.2.4",
"tslib": "2.6.0"
"@azure/identity": "3.3.0",
"tslib": "2.6.2"
}
}
15 changes: 15 additions & 0 deletions packages/graph/analytics/driveItems.ts
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;
7 changes: 7 additions & 0 deletions packages/graph/analytics/index.ts
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";
15 changes: 15 additions & 0 deletions packages/graph/analytics/listItems.ts
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;
16 changes: 16 additions & 0 deletions packages/graph/analytics/sites.ts
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;
11 changes: 11 additions & 0 deletions packages/graph/analytics/types.ts
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));
}
2 changes: 1 addition & 1 deletion packages/graph/behaviors/paged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface IPagedResult {
}

/**
* A function that will take a collection defining IGraphQueryableCollection and return the count of items
* A function that will take a collection defining IGraphCollection and return the count of items
* in that collection. Not all Graph collections support Count.
*
* @param col The collection to count
Expand Down
1 change: 0 additions & 1 deletion packages/graph/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export {
IDeltaItems,
IPreviewOptions,
IFileOptions,
IAnalyticsOptions,
} from "./types.js";

declare module "../fi" {
Expand Down
25 changes: 6 additions & 19 deletions packages/graph/files/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
graphPost,
graphPut,
} from "../graphqueryable.js";
import { Drive as IDriveType, DriveItem as IDriveItemType, ItemPreviewInfo as IDriveItemPreviewInfo, ItemAnalytics as IItemAnalytics } from "@microsoft/microsoft-graph-types";
import { Drive as IDriveType, DriveItem as IDriveItemType, ItemPreviewInfo as IDriveItemPreviewInfo } from "@microsoft/microsoft-graph-types";
import { combine } from "@pnp/core";
import { defaultPath, getById, IGetById, deleteable, IDeleteable, updateable, IUpdateable } from "../decorators.js";
import { body, BlobParse, CacheNever, errorCheck, InjectHeaders } from "@pnp/queryable";
Expand All @@ -34,7 +34,7 @@ export class _Drive extends _GraphInstance<IDriveType> {

/**
* Method for retrieving the related list resource, for use with SharePoint drives.
* @returns IGraphQueryableInstance
* @returns IGraphInstance
*/
public get list(): IGraphInstance {
return GraphInstance(this, "list");
Expand Down Expand Up @@ -128,15 +128,15 @@ export class _Root extends _GraphInstance<IDriveItemType> {
/**
* Search drive for items matching the query
* @param query string, search parameter
* @returns IGraphQueryableCollection
* @returns IGraphCollection
*/
public search(query: string): IGraphCollection {
return GraphCollection(this, `search(q='${query}')`);
}

/**
* Method for retrieving thumbnails of the drive items.
* @returns IGraphQueryableCollection
* @returns IGraphCollection
*/
public get thumbnails(): IGraphCollection {
return GraphCollection(this, "thumbnails");
Expand Down Expand Up @@ -207,7 +207,7 @@ export class _DriveItem extends _GraphInstance<IDriveItemType> {

/**
* Method for retrieving thumbnails of the drive items.
* @returns IGraphQueryableCollection
* @returns IGraphCollection
*/
public get thumbnails(): IGraphCollection {
return GraphCollection(this, "thumbnails");
Expand Down Expand Up @@ -346,17 +346,8 @@ export class _DriveItem extends _GraphInstance<IDriveItemType> {
public async preview(previewOptions?: IPreviewOptions): Promise<IDriveItemPreviewInfo> {
return graphPost(DriveItem(this, "preview"), body(previewOptions));
}

/**
* Method for getting item analytics. Defaults to lastSevenDays.
* @param analyticsOptions - IAnalyticsOptions (Optional)
* @returns IGraphQueryableCollection<IItemAnalytics>
*/
public analytics(analyticsOptions?: IAnalyticsOptions): IGraphCollection<IItemAnalytics> {
const query = `analytics/${analyticsOptions ? analyticsOptions.timeRange : "lastSevenDays"}`;
return <IGraphCollection<IItemAnalytics>>GraphCollection(this, query);
}
}

export interface IDriveItem extends _DriveItem, IDeleteable, IUpdateable { }
export const DriveItem = graphInvokableFactory<IDriveItem>(_DriveItem);

Expand Down Expand Up @@ -478,7 +469,3 @@ export interface IDeltaItems {
delta: IGraphCollection<IDeltaItems>;
values: any[];
}

export interface IAnalyticsOptions {
timeRange: "allTime" | "lastSevenDays";
}
9 changes: 9 additions & 0 deletions packages/graph/list-item/index.ts
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";
14 changes: 14 additions & 0 deletions packages/graph/list-item/list.ts
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);
54 changes: 54 additions & 0 deletions packages/graph/list-item/types.ts
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;
}
8 changes: 4 additions & 4 deletions packages/graph/lists/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById,
import { body } from "@pnp/queryable";

/**
* Represents a booking service entity
* Represents a list entity
*/
@deleteable()
@updateable()
Expand All @@ -13,14 +13,14 @@ export interface IList extends _List, IDeleteable, IUpdateable { }
export const List = graphInvokableFactory<IList>(_List);

/**
* Describes a collection of booking service objects
* Describes a collection of list objects
*
*/
@defaultPath("services")
@defaultPath("lists")
@getById(List)
export class _Lists extends _GraphCollection<IListEntity[]>{
/**
* Create a new booking service as specified in the request body.
* Create a new list as specified in the request body.
*
* @param list a JSON representation of a List object.
*/
Expand Down
Loading

0 comments on commit cdf8bda

Please sign in to comment.