@colorfullife/ms365-graph-api-auth
Advanced tools
Comparing version 2.1.3 to 2.1.4
{ | ||
"name": "@colorfullife/ms365-graph-api-auth", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "Get the authenticated Azure app to CRUD Sharepoint by Microsoft Graph API", | ||
@@ -41,3 +41,3 @@ "module": "dist/esm/index.js", | ||
}, | ||
"gitHead": "5f92922d271a47f0a36f1b2ee5d8024ced312bce" | ||
"gitHead": "415acff98345436eeb80fd43d9c354ed1e7e176d" | ||
} |
@@ -31,3 +31,3 @@ # [Microsoft 365 GraphAPI auth tool](https://www.npmjs.com/package/ms365-graph-api-auth) | ||
``` | ||
```ts | ||
require("dotenv").config(); | ||
@@ -43,3 +43,7 @@ import { getAccessToken, GraphApiQuery } from "ms365-graph-api-auth"; | ||
try { | ||
const authResponse = await getAccessToken(clientId!, clientSecret!, tenantId!); | ||
const authResponse = await getAccessToken( | ||
clientId!, | ||
clientSecret!, | ||
tenantId! | ||
); | ||
if (!authResponse) return; | ||
@@ -51,3 +55,8 @@ const query = new GraphApiQuery(authResponse.accessToken); | ||
const mySite = await query.getSites("<your-sharepoint-site-name>"); | ||
console.log({ sites: mySite.value.map((site) => ({ name: site.name, displayName: site.displayName })) }); | ||
console.log({ | ||
sites: mySite.value.map((site) => ({ | ||
name: site.name, | ||
displayName: site.displayName, | ||
})), | ||
}); | ||
// FETCH ALL SITES : await query.getSites(); | ||
@@ -58,8 +67,19 @@ | ||
// SEARCH CERTAIN LIST BY NAME | ||
const myList = await query.getListsInSite(mySite.value[0].id, "Work progress tracker"); | ||
console.log(myList.value.map((list) => ({ name: list.name, displayName: list.displayName }))); | ||
const myList = await query.getListsInSite( | ||
mySite.value[0].id, | ||
"Work progress tracker" | ||
); | ||
console.log( | ||
myList.value.map((list) => ({ | ||
name: list.name, | ||
displayName: list.displayName, | ||
})) | ||
); | ||
//3. GET ITEMS IN LIST | ||
console.log("\n\n\n3. GET ITEMS IN LIST ***"); | ||
const items = await query.getItemsInList(mySite.value[0].id, myList.value[0].id); | ||
const items = await query.getItemsInList( | ||
mySite.value[0].id, | ||
myList.value[0].id | ||
); | ||
const itemInfos = items.value.map((item) => item.fields); | ||
@@ -76,3 +96,7 @@ console.log(itemInfos.map((info) => info?.["Title"])); | ||
}; | ||
const createdItem = await query.postCreateListItem(mySite.value[0].id, myList.value[0].id, newItem); | ||
const createdItem = await query.postCreateListItem( | ||
mySite.value[0].id, | ||
myList.value[0].id, | ||
newItem | ||
); | ||
console.log(createdItem); | ||
@@ -85,3 +109,8 @@ | ||
}; | ||
const updatedItem = await query.patchUpdateListItem(mySite.value[0].id, myList.value[0].id, createdItem.id, data); | ||
const updatedItem = await query.patchUpdateListItem( | ||
mySite.value[0].id, | ||
myList.value[0].id, | ||
createdItem.id, | ||
data | ||
); | ||
console.log(updatedItem); | ||
@@ -103,3 +132,3 @@ | ||
``` | ||
```ts | ||
require("dotenv").config(); | ||
@@ -116,3 +145,7 @@ import { getAccessToken, GraphApiQuery } from "../src"; | ||
try { | ||
const authResponse = await getAccessToken(clientId!, clientSecret!, tenantId!); | ||
const authResponse = await getAccessToken( | ||
clientId!, | ||
clientSecret!, | ||
tenantId! | ||
); | ||
if (!authResponse) return; | ||
@@ -124,3 +157,8 @@ const query = new GraphApiQuery(authResponse.accessToken); | ||
const mySite = await query.getSites(process.env.SITE_NAME); | ||
console.log({ sites: mySite.value.map((site) => ({ name: site.name, displayName: site.displayName })) }); | ||
console.log({ | ||
sites: mySite.value.map((site) => ({ | ||
name: site.name, | ||
displayName: site.displayName, | ||
})), | ||
}); | ||
// FETCH ALL SITES : await query.getSites(); | ||
@@ -130,3 +168,6 @@ | ||
console.log("\n\n\n2. GET DRIVES IN CERTAIN SHAREPOINT SITE ***"); | ||
const myDrives = await query.getDrives(mySite.value[0].id, process.env.DRIVE_NAME); | ||
const myDrives = await query.getDrives( | ||
mySite.value[0].id, | ||
process.env.DRIVE_NAME | ||
); | ||
console.log(myDrives); | ||
@@ -136,3 +177,6 @@ | ||
console.log("\n\n\n3.1. GET ALL ITEMS IN CERTAIN DRIVE ***"); | ||
const myItems = await query.getDriveItems(mySite.value[0].id, myDrives.value[0].id); | ||
const myItems = await query.getDriveItems( | ||
mySite.value[0].id, | ||
myDrives.value[0].id | ||
); | ||
console.log(myItems); | ||
@@ -142,3 +186,7 @@ | ||
console.log("\n\n\n3.2. GET CERTAIN ITEM IN DRIVE BY FILE NAME ***"); | ||
const myItem1 = await query.getDriveItemByFileName(mySite.value[0].id, myDrives.value[0].id, "TainanView2.jpg"); | ||
const myItem1 = await query.getDriveItemByFileName( | ||
mySite.value[0].id, | ||
myDrives.value[0].id, | ||
"TainanView2.jpg" | ||
); | ||
console.log(myItem1); | ||
@@ -148,3 +196,7 @@ | ||
console.log("\n\n\n3.3. GET CERTAIN ITEM IN DRIVE BY FILE ID ***"); | ||
const myItem2 = await query.getDriveItemById(mySite.value[0].id, myDrives.value[0].id, myItems.value[0].id); | ||
const myItem2 = await query.getDriveItemById( | ||
mySite.value[0].id, | ||
myDrives.value[0].id, | ||
myItems.value[0].id | ||
); | ||
console.log(myItem2); | ||
@@ -171,3 +223,7 @@ | ||
console.log("\n\n\n5. DELETE DRIVE ITEM ***"); | ||
const res = await query.deleteDriveItem(mySite.value[0].id, myDrives.value[0].id, myItems.value[0].id); | ||
const res = await query.deleteDriveItem( | ||
mySite.value[0].id, | ||
myDrives.value[0].id, | ||
myItems.value[0].id | ||
); | ||
console.log(res); | ||
@@ -178,3 +234,2 @@ } catch (error) { | ||
})(); | ||
``` | ||
@@ -184,9 +239,4 @@ | ||
## 0.2.1 | ||
Checkout the [github page](https://github.com/happyeric77/colorfullife/tags) | ||
- Fix delete issue | ||
- Supports DriveItem fetch, create, upload, and delete | ||
- Add test case for Drive & DriveItem | ||
- Update readme | ||
> Any contribution will be welcome | ||
@@ -193,0 +243,0 @@ > **TODO** |
40878
230