From f33d47ca5a00efb98886c460e234fd1efc9f0b28 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Wed, 26 Jul 2023 13:42:01 -0400 Subject: [PATCH 1/5] adding pnpTest WIP --- test/core/assumptions.ts | 9 ++- test/core/storage.ts | 29 +++---- test/core/timeline.ts | 25 +++--- test/core/util.ts | 138 +++++++++++++++++++-------------- test/graph/batch.ts | 26 ++++--- test/graph/calendars.ts | 2 + test/graph/columns.ts | 138 ++++++++++++++++++++++----------- test/graph/contacts.ts | 2 + test/graph/content-types.ts | 135 ++++++++++++++++++++++---------- test/graph/directoryobjects.ts | 87 ++++++++++++--------- test/graph/groups.ts | 84 +++++++++----------- test/graph/lists.ts | 42 ++++++---- test/pnp-test.ts | 10 +++ test/test-recording.ts | 3 + 14 files changed, 447 insertions(+), 283 deletions(-) diff --git a/test/core/assumptions.ts b/test/core/assumptions.ts index 780047807..38e17eafe 100644 --- a/test/core/assumptions.ts +++ b/test/core/assumptions.ts @@ -3,10 +3,11 @@ // our assumptions remain correct import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; describe("Assumptions", function () { - it("JS should merge objects how we expect", function () { + it("JS should merge objects how we expect", pnpTest("3576d9bf-aa31-4b3f-8400-104513956328", function () { const o = {}; @@ -58,9 +59,9 @@ describe("Assumptions", function () { expect(test5, "test 5").to.eql({}); - }); + })); - it("should destructure how we assume", function () { + it("should destructure how we assume", pnpTest("67a889c9-a45a-4978-a181-91d5d096edeb", function () { const props = { yes: false, @@ -95,5 +96,5 @@ describe("Assumptions", function () { expect(title).to.eq("hello"); expect(another).to.eq("something"); - }); + })); }); diff --git a/test/core/storage.ts b/test/core/storage.ts index 81953379e..e0017430f 100644 --- a/test/core/storage.ts +++ b/test/core/storage.ts @@ -1,5 +1,6 @@ import { expect } from "chai"; import { PnPClientStorage } from "@pnp/core"; +import { pnpTest } from "../pnp-test.js"; describe("Storage", function () { @@ -7,54 +8,54 @@ describe("Storage", function () { let storage: PnPClientStorage; - beforeEach(function () { + beforeEach(pnpTest("71bacb4d-2a28-4da3-a09b-7b8625345586", function () { storage = new PnPClientStorage(); - }); + })); - it("Add and Get a value (local)", function () { + it("Add and Get a value (local)", pnpTest("4986f3f6-3b31-4ac5-9746-62384a108ae1", function () { storage.local.put("test", "value"); const ret = storage.local.get("test"); expect(ret).to.eq("value"); - }); + })); - it("Add two values, remove one and still return the other (local)", function () { + it("Add two values, remove one and still return the other (local)", pnpTest("b370742a-0eb9-40f5-bb75-43b667f51181", function () { storage.local.put("test1", "value1"); storage.local.put("test2", "value2"); storage.local.delete("test1"); const ret = storage.local.get("test2"); expect(ret).to.eq("value2"); - }); + })); - it("Use getOrPut to add a value using a getter function and return it (local)", function () { + it("Use getOrPut to add a value using a getter function and return it (local)", pnpTest("6f8a3a57-6e1e-4e26-9c86-2bfb05085c5e", function () { storage.local.getOrPut("test", function () { return new Promise(() => "value"); }).then(function () { const ret = storage.local.get("test"); expect(ret).to.eq("value"); }); - }); + })); - it("Add and Get a value (session)", function () { + it("Add and Get a value (session)", pnpTest("71cc7886-18d7-4362-b232-07afd7d6b750", function () { storage.session.put("test", "value"); const ret = storage.session.get("test"); expect(ret).to.eq("value"); - }); + })); - it("Add two values, remove one and still return the other (session)", function () { + it("Add two values, remove one and still return the other (session)", pnpTest("8c570f93-d6aa-49f3-a740-d884f1832b59", function () { storage.session.put("test1", "value1"); storage.session.put("test2", "value2"); storage.session.delete("test1"); const ret = storage.session.get("test2"); expect(ret).to.eq("value2"); - }); + })); - it("Use getOrPut to add a value using a getter function and return it (session)", function () { + it("Use getOrPut to add a value using a getter function and return it (session)", pnpTest("0c25edf5-120e-48d3-b6cd-e2da49391d21", function () { storage.session.getOrPut("test", function () { return new Promise(() => "value"); }).then(function () { const ret = storage.session.get("test"); expect(ret).to.eq("value"); }); - }); + })); }); }); diff --git a/test/core/timeline.ts b/test/core/timeline.ts index a3ab8543e..3d509f362 100644 --- a/test/core/timeline.ts +++ b/test/core/timeline.ts @@ -1,5 +1,6 @@ import { Timeline, asyncReduce } from "@pnp/core"; import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; const TestingMoments = { first: asyncReduce<(a: number) => Promise<[number]>>(), @@ -62,7 +63,7 @@ describe("Timeline", function () { return expect(h).to.eq(2); }); - it("Should process moments 2", async function () { + it("Should process moments 2", pnpTest("8267d3af-554d-44d8-8b00-e33ce7d93f1d", async function () { const tl = new TestTimeline(); @@ -78,9 +79,9 @@ describe("Timeline", function () { const h = await tl.go(0); return expect(h).to.eq(7); - }); + })); - it("Prepend works as expected", function () { + it("Prepend works as expected", pnpTest("890664f0-0e7f-4aa5-bc73-55fa4b05b27b", function () { const tl = new TestTimeline(); @@ -97,9 +98,9 @@ describe("Timeline", function () { expect(observers[0]).to.eq(f3); expect(observers[1]).to.eq(f1); expect(observers[2]).to.eq(f2); - }); + })); - it("Clear works as expected", function () { + it("Clear works as expected", pnpTest("66b43d34-7e34-4506-abc9-4d12b8286937", function () { const tl = new TestTimeline(); @@ -120,9 +121,9 @@ describe("Timeline", function () { const observers2 = tl.on.first.toArray(); expect(observers2).length(0); - }); + })); - it("Replace works as expected", function () { + it("Replace works as expected", pnpTest("b162d48e-2ddd-4b36-8fee-fc3c9ef18838", function () { const tl = new TestTimeline(); @@ -144,9 +145,9 @@ describe("Timeline", function () { expect(observers2).length(1); expect(observers2[0]).to.eq(f1); - }); + })); - it("Logging works as expected", function () { + it("Logging works as expected", pnpTest("0506ad5a-7d00-4f0e-b436-46c90faadd9d", function () { const tl = new TestTimeline(); @@ -161,9 +162,9 @@ describe("Timeline", function () { tl.log("Test 2", 0); expect(messages.length).to.eq(2); - }); + })); - it("Lifecycle works as expected", async function () { + it("Lifecycle works as expected", pnpTest("a7dda9ad-cb00-4ad8-b717-4de294e02ad2", async function () { const tl = new TestTimeline(); @@ -201,5 +202,5 @@ describe("Timeline", function () { expect(tracker[1]).to.eq(2); expect(tracker[2]).to.eq(3); expect(tracker[3]).to.eq(4); - }); + })); }); diff --git a/test/core/util.ts b/test/core/util.ts index 8c953374e..4a032bfeb 100644 --- a/test/core/util.ts +++ b/test/core/util.ts @@ -13,111 +13,122 @@ import { hOP, getHashCode, } from "@pnp/core"; +import { pnpTest } from "../pnp-test.js"; // tslint:disable:no-unused-expression describe("dateAdd", function () { - it("Add 5 Minutes", function () { + + it("Add 5 Minutes", pnpTest("e5eeda9b-2378-430c-a9d9-ac952c0b4f8e", function () { const testDate = new Date(); const checkDate = new Date(testDate.toLocaleString()); checkDate.setMinutes(testDate.getMinutes() + 5); expect(dateAdd(testDate, "minute", 5).getMinutes()).to.eq(checkDate.getMinutes()); - }); + })); - it("Add 2 Years", function () { + it("Add 2 Years", pnpTest("2a25ffc5-4f96-4f59-9a57-26ea74d1a3b5", function () { const testDate = new Date(); const checkDate = new Date(testDate.toLocaleString()); checkDate.setFullYear(testDate.getFullYear() + 2); expect(dateAdd(testDate, "year", 2).getFullYear()).to.eq(checkDate.getFullYear()); - }); + })); + }); describe("combine", function () { - it("Path (1)", function () { + + it("Path (1)", pnpTest("e8cedd77-c58d-4277-9465-6afa2e73adae", function () { expect(combine("/path/", "path2", "path3", "/path4")).to.eq("path/path2/path3/path4"); - }); + })); - it("Path (2)", function () { + it("Path (2)", pnpTest("1b9f2dc6-5b17-4573-8a65-2ef651b8972c", function () { expect(combine("http://site/path/", "/path4/page.aspx")).to.eq("http://site/path/path4/page.aspx"); - }); + })); - it("Path (3)", function () { + it("Path (3)", pnpTest("df90d9c6-c841-42f4-88d0-fb4d1a0451a5", function () { expect(combine(null, "path2", undefined, null, "/path4")).to.eq("path2/path4"); - }); + })); - it("Path (4)", function () { + it("Path (4)", pnpTest("b8564799-f0cb-4183-81a9-564e1480eba4", function () { expect(combine(null, "path2", undefined, "", null, "/path4")).to.eq("path2/path4"); - }); + })); - it("No Path", function () { + it("No Path", pnpTest("502a081f-144e-45c8-8115-c1ad4bc75d72", function () { expect(combine()).to.eq(""); - }); + })); + }); describe("getRandomString", function () { - it("Length 5", function () { + + it("Length 5", pnpTest("6c726b85-720a-4793-b5f6-2d302d16eb5b", function () { const j = getRandomString(5); expect(j).to.be.a("string"); expect(j).to.have.length(5); - }); + })); - it("Length 28", function () { + it("Length 28", pnpTest("26afbb93-8d8d-4f2a-a1c0-b3a0fb78c6bb", function () { const j = getRandomString(28); expect(j).to.be.a("string"); expect(j).to.have.length(28); - }); + })); + }); describe("getGUID", function () { - it("Test Pattern", function () { + + it("Test Pattern", pnpTest("78cd5f6d-d30a-4c0c-b44f-f55e34e39b06", function () { expect(getGUID()).to.match(/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}/i); - }); + })); + }); describe("isFunc", function () { - it("True", function () { + + it("True", pnpTest("ff0020e6-0e1b-4b12-a4a1-8a4b2fc8fcdb", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(function () { return; })).to.be.true; - }); + })); - it("False", function () { + it("False", pnpTest("ff0020e6-0e1b-4b12-a4a1-8a4b2fc8fcdb", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc({ val: 0 })).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(null)).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc(undefined)).to.be.false; - }); + })); }); describe("objectDefinedNotNull", function () { - it("defined", function () { + it("defined", pnpTest("71a58271-6205-4a7b-b651-9322a36398cc", function () { return expect(objectDefinedNotNull({})).to.be.true; - }); + })); - it("null", function () { + it("null", pnpTest("56af5be3-06e1-41b9-8183-2a9d7654052b", function () { return expect(objectDefinedNotNull(null)).to.be.false; - }); + })); - it("undefined", function () { + it("undefined", pnpTest("65dcfc1f-1c3b-488d-9bc5-3a5dd36e06a3", function () { return expect(objectDefinedNotNull(undefined)).to.be.false; - }); + })); }); describe("isArray", function () { - it("True", function () { + + it("True", pnpTest("3ad9a949-f147-47a7-868c-e1ae0fc9d65e", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray([1, 2, 3, 4])).to.be.true; - }); + })); - it("False", function () { + it("False", pnpTest("d2bb66ab-b7ed-4e3d-828a-2044d4a4ffed", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray(null)).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions @@ -128,78 +139,89 @@ describe("isArray", function () { expect(isArray({})).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isArray(undefined)).to.be.false; - }); + })); + }); describe("isUrlAbsolute", function () { - it("Yes (1)", function () { + + it("Yes (1)", pnpTest("edc77eae-ddd3-427c-aae8-863e79583c05", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("https://something.com")).to.be.true; - }); + })); - it("Yes (2)", function () { + it("Yes (2)", pnpTest("25999d21-cc28-4582-bdb5-31fa59af1191", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("//something.com")).to.be.true; - }); + })); - it("Yes (3)", function () { + it("Yes (3)", pnpTest("32547e58-299a-4979-a875-6d2dfdf324cc", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("http://something.com")).to.be.true; - }); + })); - it("No (1)", function () { + it("No (1)", pnpTest("2ee70c05-0f90-47ce-a6cf-801bf459cfca", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("/sites/dev")).to.be.false; - }); + })); - it("No (2)", function () { + it("No (2)", pnpTest("7b6b7504-fd43-4c4d-ad65-e944a11148e9", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("sites/dev")).to.be.false; - }); + })); - it("Empty", function () { + it("Empty", pnpTest("38c0cfa1-e518-47e9-a09a-7e941516dfb0", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isUrlAbsolute("")).to.be.false; - }); + })); + }); describe("stringIsNullOrEmpty", function () { - it("Yes (1)", function () { + + it("Yes (1)", pnpTest("2c88a924-49d4-4468-b4ed-47dc59341499", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty(null)).to.be.true; - }); + })); - it("Yes (2)", function () { + it("Yes (2)", pnpTest("146cfe8e-3e74-420b-bde7-feec421fb3a8", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty("")).to.be.true; - }); + })); - it("No", function () { + it("No", pnpTest("e843faac-0423-44ee-8206-00468296ea61", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(stringIsNullOrEmpty("not empty")).to.be.false; - }); + })); + }); describe("jsS", function () { + it("Sucess", function () { expect(jsS({ test: true })).to.eq("{\"test\":true}"); }); + }); describe("hOP", function () { - it("Success", function () { + + it("Success", pnpTest("f1d3a279-c51e-4c1b-a3d3-3d8ef3c747f6", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(hOP({ test: true }, "test")).to.be.true; - }); - it("Fail", function () { + })); + + it("Fail", pnpTest("d65fb0d9-be6e-4a3d-9ba9-44e85e8d6288", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(hOP({ test: true }, "nope")).to.be.false; - }); + })); }); describe("getHashCode", function () { - it("Success", function () { + + it("Success", pnpTest("dcd0ccfc-b4ff-4d9f-bd37-8a1b14d2baea", function () { expect(getHashCode("test string value")).to.be.a("number"); expect(getHashCode("test string value !@#$%^&*()_+{}<>,.?/'\"")).to.be.a("number"); - }); + })); + }); diff --git a/test/graph/batch.ts b/test/graph/batch.ts index ab6602144..69016324e 100644 --- a/test/graph/batch.ts +++ b/test/graph/batch.ts @@ -3,6 +3,7 @@ import "@pnp/graph/groups"; import "@pnp/graph/sites"; import { createBatch } from "@pnp/graph/batching"; import { expect } from "chai"; +import { pnpTest } from "../pnp-test.js"; describe("Batching", function () { @@ -13,7 +14,7 @@ describe("Batching", function () { } }); - it("Single Request", async function () { + it("Single Request", pnpTest("104a9d10-ef6f-485f-961e-45014147f52a", async function () { const order: number[] = []; const expected: number[] = [1, 2]; @@ -27,9 +28,9 @@ describe("Batching", function () { order.push(2); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Even # Requests", async function () { + it("Even # Requests", pnpTest("52bb031b-2a18-46e7-bb1b-8c0085812e0d", async function () { const order: number[] = []; const expected: number[] = [1, 2, 3]; @@ -48,9 +49,9 @@ describe("Batching", function () { order.push(3); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Odd # Requests", async function () { + it("Odd # Requests", pnpTest("0f5f9c29-7da8-483b-8c7d-4a6a9656bb92", async function () { const order: number[] = []; const expected: number[] = [1, 2, 3, 4]; @@ -72,9 +73,9 @@ describe("Batching", function () { order.push(4); return expect(order.toString()).to.eql(expected.toString()); - }); + })); - it("Should work with the same Queryable when properly cloned (Advanced)", async function () { + it("Should work with the same Queryable when properly cloned (Advanced)", pnpTest("76fbb5bf-dfc5-4230-a9df-ef1ecc2ee7a4", async function () { const users = this.pnp.graph.users; @@ -87,9 +88,9 @@ describe("Batching", function () { this.pnp.graph.users.using(batchedBehavior)(); return expect(execute()).to.eventually.be.fulfilled; - }); + })); - it("Should work with the same Queryable when properly cloned by factory (Advanced)", async function () { + it("Should work with the same Queryable when properly cloned by factory (Advanced)", pnpTest("d0ba8747-a776-4f4e-be09-6a6126dc1e06", async function () { const users = this.pnp.graph.users; @@ -101,9 +102,9 @@ describe("Batching", function () { Users(users).using(batchedBehavior)(); return expect(execute()).to.eventually.be.fulfilled; - }); + })); - it("Should fail with the same Queryable (Advanced)", async function () { + it("Should fail with the same Queryable (Advanced)", pnpTest("ca3ae3bb-1729-47d9-abea-e531cd7817dc", async function () { const users = this.pnp.graph.users; @@ -121,5 +122,6 @@ describe("Batching", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(p2).to.eventually.be.fulfilled; - }); + })); + }); diff --git a/test/graph/calendars.ts b/test/graph/calendars.ts index 68251730b..69bd1f0bc 100644 --- a/test/graph/calendars.ts +++ b/test/graph/calendars.ts @@ -5,6 +5,8 @@ import { HttpRequestError } from "@pnp/queryable"; import { stringIsNullOrEmpty } from "@pnp/core"; import getValidUser from "./utilities/getValidUser.js"; +// TODO:: test recording setup + describe("Calendar", function () { let testUserName = ""; diff --git a/test/graph/columns.ts b/test/graph/columns.ts index 161a9ab52..eaff39179 100644 --- a/test/graph/columns.ts +++ b/test/graph/columns.ts @@ -9,6 +9,7 @@ import { ISite } from "@pnp/graph/sites"; import { IContentType } from "@pnp/graph/content-types"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("Columns", function () { @@ -31,12 +32,16 @@ describe("Columns", function () { }, }; - before(async function () { + before(pnpTest("7fa03413-981c-4d51-be83-8b1b9155985a", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + templateName: getRandomString(5) + "Columns", + }); + site = await getTestingGraphSPSite(this); const ctTemplate = JSON.parse(JSON.stringify({ @@ -50,7 +55,7 @@ describe("Columns", function () { id: "0x0100CDB27E23CEF44850904C80BD666FA645", })); - ctTemplate.name += getRandomString(5) + "Columns"; + ctTemplate.name += props.templateName; const addCT = await site.contentTypes.add(ctTemplate); contentType = addCT.contentType; @@ -61,7 +66,7 @@ describe("Columns", function () { }); list = addList.list; - }); + })); after(async function () { if (list != null) { @@ -73,15 +78,16 @@ describe("Columns", function () { }); describe("Site", function () { - it("columns", async function () { + + it("columns", pnpTest("052a70b6-953b-4267-800d-900b0bf1539d", async function () { const columns = await site.columns(); expect(columns).to.be.an("array"); if (columns.length > 0) { expect(columns[0]).to.haveOwnProperty("id"); } - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("e2ebde42-c5a9-4301-9fdc-92dd711d5414", async function () { let passed = true; const columns = await site.columns(); if (columns.length > 0) { @@ -89,33 +95,50 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("7880c343-29a8-4c44-9fb3-4b39f4309c36", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name += "Add"; - columnTemplate.displayName += getRandomString(5) + "Add"; + columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplate.name)).to.be.true; - }); + })); + + it("update", pnpTest("8ce610b0-3139-4e2b-9d90-47ad43247250", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Update"; - columnTemplate.displayName += getRandomString(5) + "Update"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).update({ displayName: newColumnName }); const updateColumn = await site.columns.getById(c.data.id)(); await site.columns.getById(c.data.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; - }); + })); + + it("delete", pnpTest("bcb9bafc-4d9c-40d3-a335-b6ff9650e25c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("delete", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Delete"; - columnTemplate.displayName += getRandomString(5) + "Delete"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const c = await site.columns.add(columnTemplate); await site.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -125,24 +148,30 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); describe("Content-Type", function () { let siteColumn; - const columnTemplateName = sampleColumn.name + getRandomString(5) + "SiteColumn"; + let columnTemplateName; - before(async function () { + before(pnpTest("7b7c0559-06c7-4c7d-881e-bfc33d47c31a", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + columnTemplateName: sampleColumn.name + getRandomString(5) + "SiteColumn", + }); + + columnTemplateName = props.columnTemplateName; + const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name = columnTemplateName; columnTemplate.displayName = columnTemplateName; const addSiteCT = await site.columns.add(columnTemplate); siteColumn = addSiteCT.column; - }); + })); after(async function () { if (siteColumn != null) { @@ -150,12 +179,12 @@ describe("Columns", function () { } }); - it("columns", async function () { + it("columns", pnpTest("0312da75-4067-4d63-bb2c-e5f0d35f4b53", async function () { const columns = await contentType.columns(); return expect(columns).to.be.an("array") && expect(columns[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("d518e3f7-566d-4404-8e97-6cea48d5b1d1", async function () { let passed = true; const columns = await contentType.columns(); if (columns.length > 0) { @@ -163,23 +192,23 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); - it("addRef", async function () { + it("addRef", pnpTest("9dd8c09e-9e07-42e2-ac2d-5685966d2aa0", async function () { const c = await contentType.columns.addRef(siteColumn); await contentType.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplateName)).to.be.true; - }); + })); // Site column properties cannot be updated in content type. - it.skip("update", async function () { + it.skip("update", pnpTest("c3afb14e-3f42-48e8-9ea6-43be8d231762", async function () { const c = await contentType.columns.addRef(siteColumn); const updateColumnResults = await contentType.columns.getById(c.data.id).update({ propagateChanges: true }); await contentType.columns.getById(c.data.id).delete(); return expect((updateColumnResults.propagateChanges)).to.be.true; - }); + })); - it("delete", async function () { + it("delete", pnpTest("4d6e18c1-abe7-4cd4-a90e-1c1715d5e1ce", async function () { const c = await contentType.columns.addRef(siteColumn); await contentType.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -189,16 +218,16 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); describe("List", function () { - it("columns", async function () { + it("columns", pnpTest("2b7ff4ba-7b59-49ad-9d98-cda8bec9a012", async function () { const columns = await list.columns(); return expect(columns).to.be.an("array") && expect(columns[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("1560f120-d7da-491a-b27b-48c7b7d124ca", async function () { let passed = true; const columns = await list.columns(); if (columns.length > 0) { @@ -206,33 +235,50 @@ describe("Columns", function () { passed = (column.id === columns[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("387b5fb8-14b7-4c9a-8719-f62bc2289780", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); columnTemplate.name += "Add"; - columnTemplate.displayName += getRandomString(5) + "Add"; + columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).delete(); return expect((c.data.name === columnTemplate.name)).to.be.true; - }); + })); + + it("update", pnpTest("3827a66a-2f8b-4cd7-addb-b49eac258f45", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Update", + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Update"; - columnTemplate.displayName += getRandomString(5) + "Update"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const newColumnName = `${columnTemplate.displayName}-CHANGED`; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).update({ displayName: newColumnName }); const updateColumn = await list.columns.getById(c.data.id)(); await list.columns.getById(c.data.id).delete(); return expect((updateColumn.displayName === newColumnName)).to.be.true; - }); + })); + + it("delete", pnpTest("16650b92-045a-4bfe-8f37-a8a8856385f2", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Delete", + displayName: getRandomString(5) + "Delete", + }); - it("delete", async function () { const columnTemplate = JSON.parse(JSON.stringify(sampleColumn)); - columnTemplate.name += getRandomString(5) + "Delete"; - columnTemplate.displayName += getRandomString(5) + "Delete"; + columnTemplate.name += props.name; + columnTemplate.displayName += props.displayName; const c = await list.columns.add(columnTemplate); await list.columns.getById(c.data.id).delete(); let deletedColumn: ColumnDefinition = null; @@ -242,6 +288,6 @@ describe("Columns", function () { // do nothing } return expect(deletedColumn).to.be.null; - }); + })); }); }); diff --git a/test/graph/contacts.ts b/test/graph/contacts.ts index 43ccd17c4..817f41f9e 100644 --- a/test/graph/contacts.ts +++ b/test/graph/contacts.ts @@ -4,6 +4,8 @@ import "@pnp/graph/contacts"; import { HttpRequestError } from "@pnp/queryable"; import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; +// TODO:: make work with test recording + describe("Contacts", function () { let testUserName = ""; diff --git a/test/graph/content-types.ts b/test/graph/content-types.ts index 8e3cf65d4..0f04a3803 100644 --- a/test/graph/content-types.ts +++ b/test/graph/content-types.ts @@ -7,6 +7,7 @@ import { IList } from "@pnp/graph/lists"; import { ISite } from "@pnp/graph/sites"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("ContentTypes", function () { let site: ISite; @@ -23,21 +24,25 @@ describe("ContentTypes", function () { id: "0x0100CDB27E23CEF44850904C80BD666FA645", }; - before(async function () { + before(pnpTest("558cdcaf-dfe4-47e1-a310-7b1c4c9e5d1d", async function () { if (!this.pnp.settings.enableWebTests) { this.skip(); } + const props = await this.props({ + displayName: `PnPGraphTestContentTypes_${getRandomString(8)}`, + }); + site = await getTestingGraphSPSite(this); const listTmp = await site.lists.add({ - displayName: `PnPGraphTestContentTypes_${getRandomString(8)}`, + displayName: props.displayName, list: { "template": "genericList" }, }); list = site.lists.getById(listTmp.data.id); - }); + })); after(async function () { if (list != null) { @@ -47,12 +52,12 @@ describe("ContentTypes", function () { describe("Site", function () { - it("content types", async function () { + it("content types", pnpTest("adc47d1e-6b59-4287-a7f6-1fa42a0862e2", async function () { const ct = await site.contentTypes(); return expect(ct).to.be.an("array") && expect(ct[0]).to.haveOwnProperty("id"); - }); + })); - it("getById", async function () { + it("getById", pnpTest("ab0e1dc6-6387-404f-8acc-b8025d5aa049", async function () { let passed = true; const cts = await site.contentTypes(); if (cts.length > 0) { @@ -60,20 +65,25 @@ describe("ContentTypes", function () { passed = (ct.id === cts[0].id); } return expect(passed).is.true; - }); + })); - it("getCompatibleFromHub", async function () { + it("getCompatibleFromHub", pnpTest("42b30d81-10bf-490e-aaee-e8a2c67c8006", async function () { const cts = await site.contentTypes.getCompatibleHubContentTypes(); return expect(cts).to.be.an("array"); - }); + })); + + it("add", pnpTest("3e939430-6d79-45e9-92cf-1a296a2e0911", async function () { + + const props = await this.props({ + name: getRandomString(5) + "Add", + }); - it("add", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "Add"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).delete(); return expect((ct.data.name === ctTemplate.name)).to.be.true; - }); + })); // potential long running function - not approrpriate for automated tests it.skip("addFromHub"); @@ -82,52 +92,77 @@ describe("ContentTypes", function () { it.skip("associateWithHub"); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("isPublished", async function () { + it.skip("isPublished", pnpTest("4c3b75f9-d46e-4ae4-a1b7-8ce7bb43009c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteIsPublished", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteIsPublished"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.false; - }); + })); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("publish", async function () { + it.skip("publish", pnpTest("664acec7-ff46-4bbf-9352-16d0718767de", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SitePublish", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SitePublish"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await ct.contentType.publish(); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.true; - }); + })); // Errors with ~ Metadata hub feature is disabled on this site. - it.skip("unpublish", async function () { + it.skip("unpublish", pnpTest("28cd50ea-5672-48fc-9fc1-842c9d69688b", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteUnPublish", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteUnPublish"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await ct.contentType.publish(); await ct.contentType.unpublish(); const isPublished = await ct.contentType.isPublished(); await site.contentTypes.getById(ct.data.id).delete(); return expect(isPublished).to.be.false; - }); + })); + + it("update", pnpTest("41d3c22d-8632-4890-9ecf-7d0a367d739c", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteUpdate", + }); - it("update", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteUpdate"; + ctTemplate.name += props.name; const newContentTypeName = `${ctTemplate.name}-CHANGED`; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).update({ name: newContentTypeName }); const updateContentType = await site.contentTypes.getById(ct.data.id)(); await site.contentTypes.getById(ct.data.id).delete(); return expect((updateContentType.name === newContentTypeName)).to.be.true; - }); + })); + + it("delete", pnpTest("50a499b1-b6b9-47f7-b14e-567c03ac77a2", async function () { + + const props = await this.props({ + name: getRandomString(5) + "SiteDelete", + }); - it("delete", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "SiteDelete"; + ctTemplate.name += props.name; const ct = await site.contentTypes.add(ctTemplate); await site.contentTypes.getById(ct.data.id).delete(); let deletedContentType: ContentType = null; @@ -137,16 +172,17 @@ describe("ContentTypes", function () { // do nothing } return expect(deletedContentType).to.be.null; - }); + })); }); describe("List", function () { - it("content types", async function () { + + it("content types", pnpTest("3ee007d0-e331-4842-bc8e-8251726d9d39", async function () { const ct = await list.contentTypes(); return expect(ct).to.be.an("array") && expect(ct[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("ab0abf2f-4ffe-4d37-af4b-c8bdb8f2a257", async function () { let passed = true; const cts = await list.contentTypes(); if (cts.length > 0) { @@ -154,29 +190,39 @@ describe("ContentTypes", function () { passed = (ct.id === cts[0].id); } return expect(passed).is.true; - }); + })); - it("getCompatibleFromHub", async function () { + it("getCompatibleFromHub", pnpTest("c74f5186-5aff-4b18-b5b7-97edcd4bd6c5", async function () { const cts = await list.contentTypes.getCompatibleHubContentTypes(); return expect(cts).to.be.an("array"); - }); + })); // potential long running function - not approrpriate for automated tests it.skip("addFromHub"); - it("addCopy", async function () { + it("addCopy", pnpTest("ef5ebb3f-f8f1-4b57-a977-c3ad359365ca", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListAddCopy", + }); + const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListAddCopy"; + ctTemplate.name += props.name; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); await list.contentTypes.getById(listCT.data.id).delete(); await site.contentTypes.getById(siteCT.data.id).delete(); return expect((siteCT.data.name === listCT.data.name)).to.be.true; - }); + })); + + it("update", pnpTest("3add8b28-47ea-45a9-9db3-aa370e088f67", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListUpdate", + }); - it("update", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListUpdate"; + ctTemplate.name += props.name; const newContentTypeName = `${ctTemplate.displayName}-CHANGED`; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); @@ -185,11 +231,16 @@ describe("ContentTypes", function () { await list.contentTypes.getById(listCT.data.id).delete(); await site.contentTypes.getById(siteCT.data.id).delete(); return expect((updateContentType.name === newContentTypeName)).to.be.true; - }); + })); + + it("delete", pnpTest("5d8dc8f0-5220-400b-b990-0bcdfcd08594", async function () { + + const props = await this.props({ + name: getRandomString(5) + "ListDelete", + }); - it("delete", async function () { const ctTemplate = JSON.parse(JSON.stringify(sampleContentType)); - ctTemplate.name += getRandomString(5) + "ListDelete"; + ctTemplate.name += props.name; const siteCT = await site.contentTypes.add(ctTemplate); const listCT = await list.contentTypes.addCopy(siteCT.contentType); await list.contentTypes.getById(listCT.data.id).delete(); @@ -201,6 +252,6 @@ describe("ContentTypes", function () { // do nothing } return expect(deletedContentType).to.be.null; - }); + })); }); }); diff --git a/test/graph/directoryobjects.ts b/test/graph/directoryobjects.ts index 9ed55e2ec..edcbf600d 100644 --- a/test/graph/directoryobjects.ts +++ b/test/graph/directoryobjects.ts @@ -5,103 +5,118 @@ import "@pnp/graph/directory-objects"; import { GroupType } from "@pnp/graph/groups"; import { getRandomString, getGUID, stringIsNullOrEmpty } from "@pnp/core"; import getValidUser from "./utilities/getValidUser.js"; +import { pnpTest } from "../pnp-test.js"; describe("Directory Objects", function () { let testUserName = ""; let testChildGroupID = ""; let testParentGroupID = ""; - const testGUID = getGUID(); - let userInfo = null; + let testGUID; + let userId = null; - before(async function () { + before(pnpTest("3adea3f7-de9b-4872-92c4-82f964a072a8", async function () { if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) { this.skip(); } // Get a sample user - userInfo = await getValidUser.call(this); - testUserName = userInfo.userPrincipalName; + const userInfo = await getValidUser.call(this); + + const props = await this.props({ + groupName1: `TestGroup_${getRandomString(4)}`, + groupName2: `TestGroup_${getRandomString(4)}`, + userId: userInfo.id, + userName: userInfo.userPrincipalName, + testGuid: getGUID(), + }); + + testUserName = props.userName; + userId = props.userId; + testGUID = props.testGuid; // Create a test group to ensure we have a directory object - let groupName = `TestGroup_${getRandomString(4)}`; - let result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + + let result = await this.pnp.graph.groups.add(props.groupName1, props.groupName1, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); testChildGroupID = result.data.id; - groupName = `TestGroup_${getRandomString(4)}`; - result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + result = await this.pnp.graph.groups.add(props.groupName2, props.groupName2, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, "https://graph.microsoft.com/v1.0/groups/" + testChildGroupID, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + props.userId, ], }); testParentGroupID = result.data.id; - }); + })); - it("delete", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const result = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Security, { + it("delete", pnpTest("e1d8a9b8-43c1-4c02-85b3-92ef980d0ee2", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); + + const result = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Security, { "members@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + userId, ], "owners@odata.bind": [ - "https://graph.microsoft.com/v1.0/users/" + userInfo.id, + "https://graph.microsoft.com/v1.0/users/" + userId, ], }); const testDeleteGroupID = result.data.id; return expect(this.pnp.graph.groups.getById(testDeleteGroupID).delete()).eventually.be.fulfilled; - }); + })); - it("Get User Member Objects", async function () { + it("Get User Member Objects", pnpTest("ba2c72fb-d9f0-412d-988e-527d0ce9b7a6", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).getMemberObjects(); return expect(memberObjects).contains(testChildGroupID); - }); + })); - it("Get Group Member Objects", async function () { + it("Get Group Member Objects", pnpTest("37fe45e5-5c9b-4b45-a8a5-bd8536ecb512", async function () { const memberObjects = await this.pnp.graph.groups.getById(testChildGroupID).getMemberObjects(true); return expect(memberObjects).contains(testParentGroupID); - }); + })); - it("Get User Member Groups", async function () { + it("Get User Member Groups", pnpTest("a66c2661-e9c1-4880-a5cf-f85c04c1fc09", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).getMemberGroups(true); return expect(memberObjects).contains(testChildGroupID); - }); + })); - it("Get Group Member Objects", async function () { + it("Get Group Member Objects", pnpTest("a41f6893-7942-4584-a688-5cdef1304329", async function () { const memberObjects = await this.pnp.graph.groups.getById(testChildGroupID).getMemberGroups(); return expect(memberObjects).contains(testParentGroupID); - }); + })); - it("Check User Member Groups (1)", async function () { + it("Check User Member Groups (1)", pnpTest("fff79512-3b81-4b1f-8de2-c8c65ff3985e", async function () { const memberGroups = await this.pnp.graph.users.getById(testUserName).checkMemberGroups([testChildGroupID, testParentGroupID, testGUID]); return expect(memberGroups.length).is.equal(2); - }); + })); - it("Check User Member Groups (2)", async function () { + it("Check User Member Groups (2)", pnpTest("02172c11-b086-4fb8-a70b-216d24f17d3d", async function () { const memberGroups = await this.pnp.graph.groups.getById(testChildGroupID).checkMemberGroups([testChildGroupID, testParentGroupID, testGUID]); return expect(memberGroups.length).is.equal(1); - }); + })); - it("Get directory object by ID", async function () { + it("Get directory object by ID", pnpTest("501eef0b-1cb8-4b1e-b716-0876114f677c", async function () { const dirObj = await this.pnp.graph.directoryObjects.getById(testChildGroupID); return expect(dirObj).is.not.null; - }); + })); - it("Check MemberOf", async function () { + it("Check MemberOf", pnpTest("cfcd853b-8cba-4fea-8d1d-16afc35ba392", async function () { const memberObjects = await this.pnp.graph.users.getById(testUserName).memberOf(); return expect(memberObjects.length).greaterThan(0); - }); + })); // Remove the test data we created after(async function () { diff --git a/test/graph/groups.ts b/test/graph/groups.ts index b9704f59f..aefbba33a 100644 --- a/test/graph/groups.ts +++ b/test/graph/groups.ts @@ -2,6 +2,7 @@ import { getRandomString } from "@pnp/core"; import { expect } from "chai"; import { GroupType } from "@pnp/graph/groups"; import "@pnp/graph/sites/group"; +import { pnpTest } from "../pnp-test.js"; describe("Groups", function () { @@ -19,18 +20,26 @@ describe("Groups", function () { groupID = ""; }); - it("add", async function () { - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + it("add", pnpTest("022e5336-56a1-4bd3-80a2-74139f386e40", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); + + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); const group = await groupAddResult.group(); groupID = groupAddResult.data.id; return expect(group.displayName).is.not.undefined; - }); + })); + + it("delete", pnpTest("c6d59c80-332b-4d6d-8dbd-54c111cdcf12", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("delete", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Delete the group // Potential Bug. Delete is only available off of getByID await this.pnp.graph.groups.getById(groupAddResult.data.id).delete(); @@ -44,21 +53,29 @@ describe("Groups", function () { } }); return expect(groupExists).is.not.true; - }); + })); + + it("getById", pnpTest("ea5ae8ab-570c-48fc-b01f-331f3e6ad366", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("getById", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); // Get the group by ID const group = await this.pnp.graph.groups.getById(groupAddResult.data.id); return expect(group).is.not.undefined; - }); + })); + + it("update", pnpTest("d1845967-2d71-4995-90e0-58e8967a249a", async function () { + + const props = await this.props({ + groupName: `TestGroup_${getRandomString(4)}`, + }); - it("update", async function () { // Create a new group - const groupName = `TestGroup_${getRandomString(4)}`; - const groupAddResult = await this.pnp.graph.groups.add(groupName, groupName, GroupType.Office365); + const groupAddResult = await this.pnp.graph.groups.add(props.groupName, props.groupName, GroupType.Office365); groupID = groupAddResult.data.id; // Update the display name of the group @@ -69,10 +86,10 @@ describe("Groups", function () { // Get the group to check and see if the names are different const group = await this.pnp.graph.groups.getById(groupID)(); - return expect(groupName === group.displayName).is.not.true; - }); + return expect(props.groupName === group.displayName).is.not.true; + })); - it("sites.root.sites", async function () { + it("sites.root.sites", pnpTest("ae59d162-bb17-40f0-b606-a9b5bab3ec6c", async function () { // Find an existing group // This has to be tested on existing groups. On a newly created group, this returns an error often // "Resource provisioning is in progress. Please try again.". This is expected as the team site provisioning takes a few seconds when creating a new group @@ -83,9 +100,9 @@ describe("Groups", function () { const sitesPromise = this.pnp.graph.groups.getById(grpID).sites.root.sites(); return expect(sitesPromise).to.eventually.be.fulfilled; - }); + })); - it("sites.root", async function () { + it("sites.root", pnpTest("b5fce16b-aa14-40e3-98c5-28a828050c04", async function () { // Find an existing group const groups = await this.pnp.graph.groups(); const grpID = groups[0].id; @@ -94,32 +111,7 @@ describe("Groups", function () { const root = await this.pnp.graph.groups.getById(grpID).sites.root(); return expect(root).is.not.null; - }); - - // it("addFavorite()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("removeFavorite()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("resetUnseenCount()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("subscribeByMail()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("unsubscribeByMail()", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); - // it("getCalendarView(start: Date, end: Date)", async function () { - // // This is a user context function. Can't test in application context - // return expect(true).is.true; - // }); + })); afterEach(async function () { if (groupID !== "") { diff --git a/test/graph/lists.ts b/test/graph/lists.ts index dec278374..fbfcfa71e 100644 --- a/test/graph/lists.ts +++ b/test/graph/lists.ts @@ -5,6 +5,7 @@ import { List } from "@microsoft/microsoft-graph-types"; import { ISite } from "@pnp/graph/sites"; import { getRandomString } from "@pnp/core"; import getTestingGraphSPSite from "./utilities/getTestingGraphSPSite.js"; +import { pnpTest } from "../pnp-test.js"; describe("Lists", function () { let site: ISite; @@ -22,12 +23,12 @@ describe("Lists", function () { site = await getTestingGraphSPSite(this); }); - it("lists", async function () { + it("lists", pnpTest("016307d3-a0e3-4c8c-94e8-4f1c8566ffbd", async function () { const lists = await site.lists(); return expect(lists).to.be.an("array") && expect(lists[0]).to.haveOwnProperty("id"); - }); + })); - it("getById()", async function () { + it("getById()", pnpTest("657e7fc0-bf7d-40ed-b903-d75fe0b91d65", async function () { let passed = true; const lists = await site.lists(); if (lists.length > 0) { @@ -35,30 +36,45 @@ describe("Lists", function () { passed = (list.id === lists[0].id); } return expect(passed).is.true; - }); + })); + + it("add", pnpTest("a5b3a404-53bb-4895-815d-6681cc36fe7f", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Add", + }); - it("add", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Add"; + listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).delete(); return expect((list.data.displayName === listTemplate.displayName)).to.be.true; - }); + })); + + it("update", pnpTest("a386a85a-03ce-4846-8ca8-2472075694f5", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Update", + }); - it("update", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Update"; + listTemplate.displayName += props.displayName; const newListName = `${listTemplate.displayName}-CHANGED`; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).update({ displayName: newListName }); const updateList = await site.lists.getById(list.data.id)(); await site.lists.getById(list.data.id).delete(); return expect((updateList.displayName === newListName)).to.be.true; - }); + })); + + it("delete", pnpTest("3d070839-0713-4a3e-a718-f89bb378cbe1", async function () { + + const props = await this.props({ + displayName: getRandomString(5) + "Delete", + }); - it("delete", async function () { const listTemplate = JSON.parse(JSON.stringify(sampleList)); - listTemplate.displayName += getRandomString(5) + "Delete"; + listTemplate.displayName += props.displayName; const list = await site.lists.add(listTemplate); await site.lists.getById(list.data.id).delete(); let deletedList: List = null; @@ -68,5 +84,5 @@ describe("Lists", function () { // do nothing } return expect(deletedList).to.be.null; - }); + })); }); diff --git a/test/pnp-test.ts b/test/pnp-test.ts index 6fc4ba607..2fc338275 100644 --- a/test/pnp-test.ts +++ b/test/pnp-test.ts @@ -15,6 +15,10 @@ interface IPnPTestFunc { export const PnPTestHeaderName = "X-PnP-TestId"; +// we use this to identify tests with duplicate ids, which will cause problems +// really just a safety measure for us +const idDupeTracker = []; + /** * Behavior used to inject the correct test id into the headers for each request * @@ -46,6 +50,12 @@ function PnPTestIdHeader(id: () => string): TimelinePipe { */ export function pnpTest(id: string, testFunc: (this: IPnPTestFuncThis) => any): IPnPTestFunc { + if (idDupeTracker.indexOf(id.toLowerCase()) > -1) { + throw Error(`Test ${id} is already in use.`); + } + + idDupeTracker.push(id.toLowerCase()); + return async function (this: IPnPTestFuncThis, ...args: any[]) { this.pnpid = id; diff --git a/test/test-recording.ts b/test/test-recording.ts index 88916868d..688fa3813 100644 --- a/test/test-recording.ts +++ b/test/test-recording.ts @@ -9,6 +9,9 @@ import { default as nodeFetch } from "node-fetch"; // TODO:: a way to record tests from the browser -> console.log what we would save in a file along with the generated filename +// PS to create Guids and put them on the clip board +// "pnpTest(""$(([guid]::NewGuid() | select Guid -expandproperty Guid | Out-String).Trim())"", " | Set-Clipboard + export interface IRecordingOptions { resolvedRecordingPath: string; resolvedTestSettingsPath: string; From 7ea26338b541cd039a4b24b733695463ce2db3d4 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Thu, 10 Aug 2023 14:14:35 -0400 Subject: [PATCH 2/5] operations, site updates, file renames, rename onedrive to files --- CHANGELOG.md | 11 ++ debug/launch/graph.ts | 14 +- debug/launch/main.ts | 4 +- docs/graph/{onedrive.md => files.md} | 68 +++++----- docs/graph/operations.md | 22 +++ docs/graph/sites.md | 136 ++++++++++++++++++- mkdocs.yml | 3 +- packages/graph/attachments/types.ts | 2 +- packages/graph/batching.ts | 2 +- packages/graph/bookings/types.ts | 2 +- packages/graph/calendars/types.ts | 2 +- packages/graph/cloud-communications/types.ts | 2 +- packages/graph/columns/addColumns.ts | 2 +- packages/graph/columns/content-types.ts | 2 +- packages/graph/contacts/types.ts | 2 +- packages/graph/content-types/lists.ts | 2 +- packages/graph/content-types/sites.ts | 2 +- packages/graph/content-types/types.ts | 2 +- packages/graph/conversations/types.ts | 2 +- packages/graph/decorators.ts | 2 +- packages/graph/directory-objects/types.ts | 2 +- packages/graph/{onedrive => files}/funcs.ts | 6 +- packages/graph/{onedrive => files}/groups.ts | 0 packages/graph/{onedrive => files}/index.ts | 1 + packages/graph/{onedrive => files}/sites.ts | 0 packages/graph/{onedrive => files}/types.ts | 2 +- packages/graph/{onedrive => files}/users.ts | 2 +- packages/graph/groups/types.ts | 2 +- packages/graph/index.ts | 2 +- packages/graph/invitations/types.ts | 2 +- packages/graph/lists/drive.ts | 4 +- packages/graph/lists/types.ts | 2 +- packages/graph/members/types.ts | 2 +- packages/graph/messages/users.ts | 2 +- packages/graph/onenote/types.ts | 2 +- packages/graph/operations/index.ts | 7 + packages/graph/operations/list.ts | 14 ++ packages/graph/operations/site.ts | 14 ++ packages/graph/operations/types.ts | 11 ++ packages/graph/{operations.ts => ops.ts} | 0 packages/graph/photos/types.ts | 2 +- packages/graph/planner/types.ts | 2 +- packages/graph/presets/all.ts | 6 +- packages/graph/search/types.ts | 2 +- packages/graph/shares/types.ts | 2 +- packages/graph/sites/index.ts | 1 + packages/graph/sites/types.ts | 56 +++++++- packages/graph/sites/user.ts | 14 ++ packages/graph/subscriptions/types.ts | 2 +- packages/graph/teams/index.ts | 2 +- packages/graph/teams/types.ts | 2 +- packages/sp/appcatalog/types.ts | 2 +- packages/sp/attachments/types.ts | 2 +- packages/sp/batching.ts | 2 +- packages/sp/behaviors/request-digest.ts | 2 +- packages/sp/clientside-pages/types.ts | 2 +- packages/sp/clientside-pages/web.ts | 2 +- packages/sp/column-defaults/list.ts | 2 +- packages/sp/comments/clientside-page.ts | 2 +- packages/sp/comments/item.ts | 2 +- packages/sp/comments/types.ts | 2 +- packages/sp/content-types/types.ts | 2 +- packages/sp/context-info/index.ts | 2 +- packages/sp/favorites/types.ts | 2 +- packages/sp/features/types.ts | 2 +- packages/sp/fields/types.ts | 2 +- packages/sp/files/types.ts | 2 +- packages/sp/folders/types.ts | 2 +- packages/sp/hubsites/site.ts | 2 +- packages/sp/hubsites/web.ts | 2 +- packages/sp/index.ts | 2 +- packages/sp/items/types.ts | 2 +- packages/sp/lists/types.ts | 2 +- packages/sp/navigation/types.ts | 2 +- packages/sp/{operations.ts => ops.ts} | 0 packages/sp/profiles/types.ts | 2 +- packages/sp/recycle-bin/types.ts | 2 +- packages/sp/regional-settings/funcs.ts | 2 +- packages/sp/regional-settings/types.ts | 2 +- packages/sp/related-items/types.ts | 2 +- packages/sp/search/query.ts | 2 +- packages/sp/security/funcs.ts | 2 +- packages/sp/security/types.ts | 2 +- packages/sp/sharing/funcs.ts | 2 +- packages/sp/sharing/web.ts | 2 +- packages/sp/site-designs/types.ts | 2 +- packages/sp/site-groups/types.ts | 2 +- packages/sp/site-groups/web.ts | 2 +- packages/sp/site-scripts/types.ts | 2 +- packages/sp/site-users/types.ts | 2 +- packages/sp/site-users/web.ts | 2 +- packages/sp/sites/types.ts | 2 +- packages/sp/social/types.ts | 2 +- packages/sp/spqueryable.ts | 2 +- packages/sp/sputilities/types.ts | 2 +- packages/sp/subscriptions/types.ts | 2 +- packages/sp/taxonomy/types.ts | 2 +- packages/sp/user-custom-actions/types.ts | 2 +- packages/sp/views/types.ts | 2 +- packages/sp/webparts/types.ts | 2 +- packages/sp/webs/types.ts | 2 +- test/graph/onedrive.ts | 4 +- test/graph/querable.ts | 2 +- test/graph/sites.ts | 5 +- 104 files changed, 422 insertions(+), 139 deletions(-) rename docs/graph/{onedrive.md => files.md} (93%) create mode 100644 docs/graph/operations.md rename packages/graph/{onedrive => files}/funcs.ts (84%) rename packages/graph/{onedrive => files}/groups.ts (100%) rename packages/graph/{onedrive => files}/index.ts (97%) rename packages/graph/{onedrive => files}/sites.ts (100%) rename packages/graph/{onedrive => files}/types.ts (99%) rename packages/graph/{onedrive => files}/users.ts (97%) create mode 100644 packages/graph/operations/index.ts create mode 100644 packages/graph/operations/list.ts create mode 100644 packages/graph/operations/site.ts create mode 100644 packages/graph/operations/types.ts rename packages/graph/{operations.ts => ops.ts} (100%) create mode 100644 packages/graph/sites/user.ts rename packages/sp/{operations.ts => ops.ts} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4ab9740e..06b0901d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- graph + - limitation on chaining site operations from sites.getByUrl + ### Added - graph - explict error thrown if SPFx context is null or undefined when needed + - followed sites support for users + - ISite now supports `async rebase()` to ensure any ISite is represented by the url pattern /sites/{site id} regardless of how it was first loaded + - ISites.getAllSites() + - support for operations for ISite and IList - sp - explict error thrown if SPFx context is null or undefined when needed @@ -26,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - getPaged method removed from _Items/IItems - PagedItemCollection removed from library - removed /items/get-all import, unneeded, use async iterator patterns + - operations.ts renamed to ops.ts ### Changed @@ -33,6 +41,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - IGraphQueryableCollection now supports async iterator pattern - IGraphQueryableCollection count method now returns -1 if the collection does not support counting - All GraphQueryable*, _GraphQueryable*, and IGraphQueryable* have been renamed to remove "Queryable" (ex: GraphQueryableCollection is now GraphCollection) + - @pnp/graph/onedrive renamed to @pnp/graph/files + - ISites.getByUrl is now async + - operations.ts renamed to ops.ts - sp - _Items and IItems now supports async iterator pattern diff --git a/debug/launch/graph.ts b/debug/launch/graph.ts index f2646a551..5aa4c6498 100644 --- a/debug/launch/graph.ts +++ b/debug/launch/graph.ts @@ -1,6 +1,9 @@ import { Logger, LogLevel } from "@pnp/logging"; import { graphSetup } from "./setup.js"; +import "@pnp/graph/sites"; import "@pnp/graph/users"; +import "@pnp/graph/files"; +import "@pnp/graph/operations"; declare var process: { exit(code?: number): void }; @@ -8,13 +11,16 @@ export async function Example(settings: any) { const graph = graphSetup(settings); - const users = await graph.users(); - + const site = await graph.sites.getByUrl("318studios.sharepoint.com", "/sites/dev") + + const ops = await site.operations(); + + Logger.log({ - data: users, + data: ops, level: LogLevel.Info, message: "List of Users Data", }); process.exit(0); -} \ No newline at end of file +} diff --git a/debug/launch/main.ts b/debug/launch/main.ts index 2a4fdec1e..9c9922e07 100644 --- a/debug/launch/main.ts +++ b/debug/launch/main.ts @@ -8,8 +8,8 @@ import { ITestingSettings } from "../../test/load-settings.js"; // add your debugging imports here and prior to submitting a PR git checkout debug/debug.ts // will allow you to keep all your debugging files locally // comment out the example -import { Example } from "./sp.js"; -// import { Example } from "./graph.js"; +// import { Example } from "./sp.js"; +import { Example } from "./graph.js"; // setup the connection to SharePoint using the settings file, you can // override any of the values as you want here, just be sure not to commit diff --git a/docs/graph/onedrive.md b/docs/graph/files.md similarity index 93% rename from docs/graph/onedrive.md rename to docs/graph/files.md index fb4f968ad..d1e0896a8 100644 --- a/docs/graph/onedrive.md +++ b/docs/graph/files.md @@ -1,4 +1,4 @@ -# @pnp/graph/onedrive +# @pnp/graph/files The ability to manage drives and drive items in Onedrive is a capability introduced in version 1.2.4 of @pnp/graph. Through the methods described you can manage drives and drive items in Onedrive. @@ -16,7 +16,7 @@ import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/groups"; import "@pnp/graph/sites"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -38,7 +38,7 @@ import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/groups"; import "@pnp/graph/sites"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -59,7 +59,7 @@ Using the drives.getById() you can get one of the available drives in Outlook ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -78,7 +78,7 @@ Using the list() you get the associated list information ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -94,7 +94,7 @@ Form more infomration about acting on the IList object see [@pnpjs/graph/lists]( ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import "@pnp/graph/lists"; const graph = graphfi(...); @@ -113,7 +113,7 @@ Using the recent() you get the recent files ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -130,7 +130,7 @@ Using the sharedWithMe() you get the files shared with the user ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -152,7 +152,7 @@ List the items that have been followed by the signed in user. ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -169,7 +169,7 @@ import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/sites"; import "@pnp/graph/groups"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -194,7 +194,7 @@ Using the children() you get the children ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -215,7 +215,7 @@ Using the drive.getItemsByPath() you can get the contents of a particular folder ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -231,9 +231,9 @@ Using the add you can add an item, for more options please user the upload metho ```TypeScript import { graphfi } from "@pnp/graph"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import "@pnp/graph/users"; -import {IDriveItemAddResult} from "@pnp/graph/onedrive"; +import {IDriveItemAddResult} from "@pnp/graph/files"; const graph = graphfi(...); @@ -247,9 +247,9 @@ Using the .upload method you can add or update the content of an item. ```TypeScript import { graphfi } from "@pnp/graph"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import "@pnp/graph/users"; -import {IFileOptions, IDriveItemAddResult} from "@pnp/graph/onedrive"; +import {IFileOptions, IDriveItemAddResult} from "@pnp/graph/files"; const graph = graphfi(...); @@ -282,7 +282,7 @@ Using addFolder you can add a folder ```TypeScript import { graph } from "@pnp/graph"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import "@pnp/graph/users" import {IDriveItemAddResult} from "@pnp/graph/ondrive"; @@ -300,7 +300,7 @@ Using the search() you can search for items, and optionally select properties ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -320,7 +320,7 @@ Using the items.getById() you can get a specific item from the current drive ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -337,7 +337,7 @@ Using the drive.getItemByPath() you can get a specific item from the current dri ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -354,7 +354,7 @@ Using the item.getContent() you can get the content of a file. ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -385,7 +385,7 @@ Using the item.convertContent() you can get a PDF version of the file. See [offi ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -414,7 +414,7 @@ Using the thumbnails() you get the thumbnails ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -431,7 +431,7 @@ Using the delete() you delete the current item ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -448,7 +448,7 @@ Using the update() you update the current item ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -465,7 +465,7 @@ Using the move() you move the current item, and optionally update it ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -491,7 +491,7 @@ Using the copy() you can copy the current item to a new location, returns the pa ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; const graph = graphfi(...); @@ -517,8 +517,8 @@ Using the users default drive you can get special folders, including: Documents, ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; -import { SpecialFolder, IDriveItem } from "@pnp/graph/onedrive"; +import "@pnp/graph/files"; +import { SpecialFolder, IDriveItem } from "@pnp/graph/files"; const graph = graphfi(...); @@ -540,8 +540,8 @@ If you want to obtain long-lived embeddable links, use the createLink API instea ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; -import { IPreviewOptions, IDriveItemPreviewInfo } from "@pnp/graph/onedrive"; +import "@pnp/graph/files"; +import { IPreviewOptions, IDriveItemPreviewInfo } from "@pnp/graph/files"; import { ItemPreviewInfo } from "@microsoft/microsoft-graph-types" const graph = graphfi(...); @@ -566,7 +566,7 @@ Track changes in a driveItem and its children over time. ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import { IDeltaItems } from "@pnp/graph/ondrive"; const graph = graphfi(...); @@ -596,8 +596,8 @@ Using the analytics() you get the ItemAnalytics for a DriveItem ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; -import { IAnalyticsOptions } from "@pnp/graph/onedrive"; +import "@pnp/graph/files"; +import { IAnalyticsOptions } from "@pnp/graph/files"; const graph = graphfi(...); diff --git a/docs/graph/operations.md b/docs/graph/operations.md new file mode 100644 index 000000000..d0d6f0afb --- /dev/null +++ b/docs/graph/operations.md @@ -0,0 +1,22 @@ +# @pnp/graph/operations + +Provides capabilities related to rich long-running operations. + +[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) + +## list site operations + +```TypeScript +import "@pnp/graph/sites"; +import "@pnp/graph/operations"; + +const graph = graphfi(...); + +// using getByUrl +const site = await graph.sites.getByUrl("tenant.sharepoint.com", "/sites/dev"); + +const ops = await site.operations(); + +// using site id +const ops2 = await graph.sites.getById("{site id}").operations(); +``` diff --git a/docs/graph/sites.md b/docs/graph/sites.md index 44070b32d..f03603f09 100644 --- a/docs/graph/sites.md +++ b/docs/graph/sites.md @@ -4,7 +4,9 @@ The search module allows you to access the Microsoft Graph Sites API. [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) -## Call graph.sites +## sites + +### list ```TypeScript import { graphfi } from "@pnp/graph"; @@ -15,7 +17,7 @@ const graph = graphfi(...); const sitesInfo = await graph.sites(); ``` -## Call graph.sites.getById +### getById ```TypeScript import { graphfi } from "@pnp/graph"; @@ -26,12 +28,10 @@ const graph = graphfi(...); const siteInfo = await graph.sites.getById("{site identifier}")(); ``` -## Call graph.sites.getByUrl +### getByUrl Using the sites.getByUrl() you can get a site using url instead of identifier -![Known Issue Banner](https://img.shields.io/badge/Known%20Issue-important.svg) If you get a site with this method, the graph does not support chaining a request further than .drive. We will review and try and create a work around for this issue. - ```TypeScript import { graphfi } from "@pnp/graph"; import "@pnp/graph/sites"; @@ -42,6 +42,128 @@ const serverRelativeUrl = "/sites/teamsite1"; const siteInfo = await graph.sites.getByUrl(sharepointHostName, serverRelativeUrl)(); ``` -## Make additional calls or recieve items from lists +### getAllSites + +List sites across geographies in an organization. This API can also be used to enumerate all sites in a non-multi-geo tenant. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; + +const graph = graphfi(...); + +const siteslist = []; + +// use async iterator pattern +for await (const sites of graph.sites.getAllSites()) { + siteslist.push(sites); +} + +// supports query params, here we get the sites in pages of 5 as an example +for await (const sites of graph.sites.getAllSites().top(5)) { + siteslist.push(sites); +} +``` + +## site + +### get + +Access sub-sites of the current site + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; + +const graph = graphfi(...); + +const siteInfo = await graph.sites.getById("{site id}")(); +``` + +### sites + +Access sub-sites of the current site + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; + +const graph = graphfi(...); + +const subsites = await graph.sites.getById("{site id}").sites(); +``` + +### rebase + +Ensures the underlying url used in queries for this site is of the pattern /sites/{site id} regardless of how the ISite instance was addressed. + +>> We internally rebase sites using this method so you probably don't need to call it directly, but it is available in case you do😀 + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; -We don't currently implement all of the available options in graph for sites, rather focusing on the sp library. While we do accept PRs to add functionality, you can [also make calls by path.](./items.md) +const graph = graphfi(...); + +const rebasedSite = await Site([graph.sites, "/sites/tenant.sharepoint.com:/sites/dev:"]).rebase(); + +const items = await rebasedSite.drive.root.children(); +``` + +## followedSites + +Provides access to the sites a user is following. + +### list + +>> At this time you can not list a user's followed sites using app-only permissions + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/users"; + +const graph = graphfi(...); + +const followedSites = await graph.me.followedSites(); +``` + +### add + +Adds a followed site to a user's collection + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/users"; + +const graph = graphfi(...); + +const followedSites = await graph.me.followedSites.add("{site id}"); + +// supports multiple ids in a single call +const followedSites2 = await graph.me.followedSites.add("{site id}", "{site id2}", "{site id3}", "{site id4}"); + +// callable for any user +const followedSites3 = await graph.users.getById("{user id}").followedSites.add("{site id}", "{site id2}", "{site id3}", "{site id4}"); +``` + +### remove + +Removes a followed site to a user's collection + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/users"; + +const graph = graphfi(...); + +await graph.me.followedSites.remove("{site id}"); + +// supports multiple ids in a single call +await graph.me.followedSites.remove("{site id}", "{site id2}", "{site id3}", "{site id4}"); + +// callable for any user +await graph.users.getById("{user id}").followedSites.remove("{site id}", "{site id2}", "{site id3}", "{site id4}"); +``` diff --git a/mkdocs.yml b/mkdocs.yml index d1592830d..a0d11c4da 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -49,12 +49,13 @@ nav: - 'cloud communications': 'graph/cloud-communications.md' - calendars: 'graph/calendars.md' - 'directory objects': 'graph/directoryobjects.md' + - files: 'graph/files.md' - invitations: 'graph/invitations.md' - items: 'graph/items.md' - lists: 'graph/lists.md' - messages: 'graph/messages.md' - - onedrive: 'graph/onedrive.md' - outlook: 'graph/outlook.md' + - operations: 'graph/operations.md' - photos: 'graph/photos.md' - planner: 'graph/planner.md' - search: 'graph/search.md' diff --git a/packages/graph/attachments/types.ts b/packages/graph/attachments/types.ts index 5559242c9..781377439 100644 --- a/packages/graph/attachments/types.ts +++ b/packages/graph/attachments/types.ts @@ -1,7 +1,7 @@ import { Attachment as IAttachmentType } from "@microsoft/microsoft-graph-types"; import { body } from "@pnp/queryable"; import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; import { type } from "../utils/type.js"; diff --git a/packages/graph/batching.ts b/packages/graph/batching.ts index 5e306a203..6dd53cfa4 100644 --- a/packages/graph/batching.ts +++ b/packages/graph/batching.ts @@ -1,7 +1,7 @@ import { isUrlAbsolute, hOP, TimelinePipe, getGUID, CopyFrom, objectDefinedNotNull, isFunc, combine } from "@pnp/core"; import { parseBinderWithErrorCheck, Queryable, body, InjectHeaders } from "@pnp/queryable"; import { IGraphQueryable, _GraphQueryable } from "./graphqueryable.js"; -import { graphPost } from "./operations.js"; +import { graphPost } from "./ops.js"; import { GraphFI } from "./fi.js"; declare module "./fi" { diff --git a/packages/graph/bookings/types.ts b/packages/graph/bookings/types.ts index 15386a817..4563ed14c 100644 --- a/packages/graph/bookings/types.ts +++ b/packages/graph/bookings/types.ts @@ -9,7 +9,7 @@ import { } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { calendarView } from "./funcs.js"; diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 5f3327999..049eb417c 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -2,7 +2,7 @@ import { body } from "@pnp/queryable"; import { Event as IEventType, Calendar as ICalendarType } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath, IDeleteable, deleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { calendarView, instances } from "./funcs.js"; /** diff --git a/packages/graph/cloud-communications/types.ts b/packages/graph/cloud-communications/types.ts index 330513d31..c714db00f 100644 --- a/packages/graph/cloud-communications/types.ts +++ b/packages/graph/cloud-communications/types.ts @@ -2,7 +2,7 @@ import { Presence as IUserPresence } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; import { defaultPath } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/columns/addColumns.ts b/packages/graph/columns/addColumns.ts index 76c383e6c..924944d38 100644 --- a/packages/graph/columns/addColumns.ts +++ b/packages/graph/columns/addColumns.ts @@ -1,5 +1,5 @@ import { IColumn } from "./types"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { ColumnDefinition as IColumnDefinition, diff --git a/packages/graph/columns/content-types.ts b/packages/graph/columns/content-types.ts index 83f2e8c28..3c0e4c1cf 100644 --- a/packages/graph/columns/content-types.ts +++ b/packages/graph/columns/content-types.ts @@ -1,5 +1,5 @@ import { addProp, body } from "@pnp/queryable"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { _ContentType } from "../content-types/types.js"; import { Columns, IColumns,IColumn, _Columns } from "./types.js"; import { IColumnAddResult } from "./addColumns.js"; diff --git a/packages/graph/contacts/types.ts b/packages/graph/contacts/types.ts index 20df7a944..a73e662f9 100644 --- a/packages/graph/contacts/types.ts +++ b/packages/graph/contacts/types.ts @@ -1,7 +1,7 @@ import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; import { Contact as IContactType, ContactFolder as IContactFolderType, EmailAddress as IEmailAddressType } from "@microsoft/microsoft-graph-types"; import { defaultPath, updateable, deleteable, IUpdateable, IDeleteable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/content-types/lists.ts b/packages/graph/content-types/lists.ts index e1dbb8a3b..5d8a5b026 100644 --- a/packages/graph/content-types/lists.ts +++ b/packages/graph/content-types/lists.ts @@ -1,5 +1,5 @@ import { addProp } from "@pnp/queryable"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { _List } from "../lists/types.js"; import { ContentTypes, IContentType, IContentTypeAddResult, IContentTypes, _ContentTypes } from "./types.js"; import { body } from "@pnp/queryable"; diff --git a/packages/graph/content-types/sites.ts b/packages/graph/content-types/sites.ts index 2e6e4aadc..015b0f683 100644 --- a/packages/graph/content-types/sites.ts +++ b/packages/graph/content-types/sites.ts @@ -2,7 +2,7 @@ import { addProp } from "@pnp/queryable"; import { ContentType as IContentTypeEntity, } from "@microsoft/microsoft-graph-types"; -import { graphGet, graphPost } from "../operations.js"; +import { graphGet, graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { Site, _Site } from "../sites/types.js"; import { ContentTypes, IContentType, IContentTypeAddResult, IContentTypes, _ContentTypes } from "./types.js"; diff --git a/packages/graph/content-types/types.ts b/packages/graph/content-types/types.ts index 4c13cf885..1477519b7 100644 --- a/packages/graph/content-types/types.ts +++ b/packages/graph/content-types/types.ts @@ -4,7 +4,7 @@ import { } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphGet, graphPost } from "../operations.js"; +import { graphGet, graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { JSONHeaderParse } from "@pnp/queryable"; diff --git a/packages/graph/conversations/types.ts b/packages/graph/conversations/types.ts index 845080daa..2a808f50b 100644 --- a/packages/graph/conversations/types.ts +++ b/packages/graph/conversations/types.ts @@ -12,7 +12,7 @@ import { graphInvokableFactory, } from "../graphqueryable.js"; import { defaultPath, updateable, IUpdateable, deleteable, IDeleteable, addable, IAddable, getById, IGetById } from "../decorators.js"; -import { graphPost, graphDelete } from "../operations.js"; +import { graphPost, graphDelete } from "../ops.js"; /** * Conversation diff --git a/packages/graph/decorators.ts b/packages/graph/decorators.ts index 79a3a59f4..c56e8a951 100644 --- a/packages/graph/decorators.ts +++ b/packages/graph/decorators.ts @@ -1,5 +1,5 @@ import { IGraphQueryable } from "./graphqueryable.js"; -import { graphDelete, graphPatch, graphPost } from "./operations.js"; +import { graphDelete, graphPatch, graphPost } from "./ops.js"; import { body, headers } from "@pnp/queryable"; /** diff --git a/packages/graph/directory-objects/types.ts b/packages/graph/directory-objects/types.ts index 71b72c91d..e266c8dac 100644 --- a/packages/graph/directory-objects/types.ts +++ b/packages/graph/directory-objects/types.ts @@ -2,7 +2,7 @@ import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../grap import { DirectoryObject as IDirectoryObjectType } from "@microsoft/microsoft-graph-types"; import { defaultPath, getById, IGetById, deleteable, IDeleteable } from "../decorators.js"; import { body } from "@pnp/queryable"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { Count } from "../behaviors/paged.js"; /** diff --git a/packages/graph/onedrive/funcs.ts b/packages/graph/files/funcs.ts similarity index 84% rename from packages/graph/onedrive/funcs.ts rename to packages/graph/files/funcs.ts index a0e20f5c6..0d5af81fa 100644 --- a/packages/graph/onedrive/funcs.ts +++ b/packages/graph/files/funcs.ts @@ -1,6 +1,6 @@ import { combine } from "@pnp/core"; import { body, InjectHeaders } from "@pnp/queryable"; -import { graphPost, graphPut } from "../operations.js"; +import { graphPost, graphPut } from "../ops.js"; import { DriveItem, IDriveItemAddResult, IFileOptions } from "./types.js"; export interface ICheckInOptions { @@ -16,6 +16,10 @@ export function checkOut(): Promise { return graphPost(DriveItem(this, "checkout")); } +export function encodeSharingUrl(url: string): string { + return "u!" + Buffer.from(url, "utf8").toString("base64").replace(/=$/i, "").replace("/", "_").replace("+", "-"); +} + export async function driveItemUpload(fileOptions: IFileOptions): Promise { let path = "/content"; if (fileOptions.filePathName) { diff --git a/packages/graph/onedrive/groups.ts b/packages/graph/files/groups.ts similarity index 100% rename from packages/graph/onedrive/groups.ts rename to packages/graph/files/groups.ts diff --git a/packages/graph/onedrive/index.ts b/packages/graph/files/index.ts similarity index 97% rename from packages/graph/onedrive/index.ts rename to packages/graph/files/index.ts index 7e46ed940..8e7bf5ef4 100644 --- a/packages/graph/onedrive/index.ts +++ b/packages/graph/files/index.ts @@ -10,6 +10,7 @@ export { export { ICheckInOptions, + encodeSharingUrl, } from "./funcs.js"; export { diff --git a/packages/graph/onedrive/sites.ts b/packages/graph/files/sites.ts similarity index 100% rename from packages/graph/onedrive/sites.ts rename to packages/graph/files/sites.ts diff --git a/packages/graph/onedrive/types.ts b/packages/graph/files/types.ts similarity index 99% rename from packages/graph/onedrive/types.ts rename to packages/graph/files/types.ts index 1f7b269be..e145006a9 100644 --- a/packages/graph/onedrive/types.ts +++ b/packages/graph/files/types.ts @@ -12,7 +12,7 @@ import { Drive as IDriveType, DriveItem as IDriveItemType, ItemPreviewInfo as ID 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"; -import { graphPatch, graphPost, graphPut } from "../operations.js"; +import { graphPatch, graphPost, graphPut } from "../ops.js"; import { driveItemUpload } from "./funcs.js"; /** diff --git a/packages/graph/onedrive/users.ts b/packages/graph/files/users.ts similarity index 97% rename from packages/graph/onedrive/users.ts rename to packages/graph/files/users.ts index 0fbdebdeb..d144214a1 100644 --- a/packages/graph/onedrive/users.ts +++ b/packages/graph/files/users.ts @@ -1,5 +1,5 @@ import { addProp, body } from "@pnp/queryable"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { _User } from "../users/types.js"; import { IDrive, Drive, IDrives, Drives, _Drive, DriveItem, IDriveItem, _DriveItem, IItemOptions } from "./types.js"; diff --git a/packages/graph/groups/types.ts b/packages/graph/groups/types.ts index 43fae39d1..8926cf71d 100644 --- a/packages/graph/groups/types.ts +++ b/packages/graph/groups/types.ts @@ -2,7 +2,7 @@ import { Event as IEventType, Group as IGroupType } from "@microsoft/microsoft-g import { body } from "@pnp/queryable"; import { graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { _DirectoryObject, _DirectoryObjects } from "../directory-objects/types.js"; export enum GroupType { diff --git a/packages/graph/index.ts b/packages/graph/index.ts index a8fc86fcd..50ee4be80 100644 --- a/packages/graph/index.ts +++ b/packages/graph/index.ts @@ -10,7 +10,7 @@ export { IGraphConstructor, } from "./graphqueryable.js"; -export * from "./operations.js"; +export * from "./ops.js"; export * from "./behaviors/consistency-level.js"; export * from "./behaviors/defaults.js"; diff --git a/packages/graph/invitations/types.ts b/packages/graph/invitations/types.ts index ba5d7c0e9..959fad8b0 100644 --- a/packages/graph/invitations/types.ts +++ b/packages/graph/invitations/types.ts @@ -2,7 +2,7 @@ import { body } from "@pnp/queryable"; import { Invitation as IInvitationType } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; /** * Invitations diff --git a/packages/graph/lists/drive.ts b/packages/graph/lists/drive.ts index 4ee478c90..84b2eb6f3 100644 --- a/packages/graph/lists/drive.ts +++ b/packages/graph/lists/drive.ts @@ -1,7 +1,7 @@ -import { _Drive } from "../onedrive/types.js"; +import { _Drive } from "../files/types.js"; import { List, IList } from "./types.js"; -declare module "../onedrive/types" { +declare module "../files/types" { interface _Drive { getList: () => Promise; } diff --git a/packages/graph/lists/types.ts b/packages/graph/lists/types.ts index 4bf1fd44c..209797538 100644 --- a/packages/graph/lists/types.ts +++ b/packages/graph/lists/types.ts @@ -1,7 +1,7 @@ import { List as IListEntity } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/members/types.ts b/packages/graph/members/types.ts index b52949ef0..e531aaa34 100644 --- a/packages/graph/members/types.ts +++ b/packages/graph/members/types.ts @@ -2,7 +2,7 @@ import { body } from "@pnp/queryable"; import { User as IMemberType } from "@microsoft/microsoft-graph-types"; import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; -import { graphDelete, graphPost } from "../operations.js"; +import { graphDelete, graphPost } from "../ops.js"; /** * Member diff --git a/packages/graph/messages/users.ts b/packages/graph/messages/users.ts index 0712770bd..44cd0f8a5 100644 --- a/packages/graph/messages/users.ts +++ b/packages/graph/messages/users.ts @@ -1,7 +1,7 @@ import { addProp, body } from "@pnp/queryable"; import { _User, User } from "../users/types.js"; import { IMessages, Messages, IMailboxSettings, MailboxSettings, IMailFolders, MailFolders, IMessage } from "./types.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; declare module "../users/types" { interface _User { diff --git a/packages/graph/onenote/types.ts b/packages/graph/onenote/types.ts index 661ca8460..03b501d6c 100644 --- a/packages/graph/onenote/types.ts +++ b/packages/graph/onenote/types.ts @@ -8,7 +8,7 @@ import { graphInvokableFactory, } from "../graphqueryable.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; /** * Represents a onenote entity diff --git a/packages/graph/operations/index.ts b/packages/graph/operations/index.ts new file mode 100644 index 000000000..0af3486dd --- /dev/null +++ b/packages/graph/operations/index.ts @@ -0,0 +1,7 @@ +import "./site.js"; +import "./list.js"; + +export { + IOperations, + Operations, +} from "./types.js"; diff --git a/packages/graph/operations/list.ts b/packages/graph/operations/list.ts new file mode 100644 index 000000000..69eccee9e --- /dev/null +++ b/packages/graph/operations/list.ts @@ -0,0 +1,14 @@ +import { addProp } from "@pnp/queryable"; +import { _List } from "../lists/types.js"; +import { IOperations, Operations } from "./types.js"; + +declare module "../lists/types" { + interface _List { + readonly operations: IOperations; + } + interface IList { + readonly operations: IOperations; + } +} + +addProp(_List, "operations", Operations); diff --git a/packages/graph/operations/site.ts b/packages/graph/operations/site.ts new file mode 100644 index 000000000..dca398b4d --- /dev/null +++ b/packages/graph/operations/site.ts @@ -0,0 +1,14 @@ +import { addProp } from "@pnp/queryable"; +import { _Site } from "../sites/types.js"; +import { IOperations, Operations } from "./types.js"; + +declare module "../sites/types" { + interface _Site { + readonly operations: IOperations; + } + interface ISite { + readonly operations: IOperations; + } +} + +addProp(_Site, "operations", Operations); diff --git a/packages/graph/operations/types.ts b/packages/graph/operations/types.ts new file mode 100644 index 000000000..7c12c4787 --- /dev/null +++ b/packages/graph/operations/types.ts @@ -0,0 +1,11 @@ +import { defaultPath } from "../decorators.js"; +import { graphInvokableFactory, _GraphCollection } from "../graphqueryable.js"; +import { Operation as IOperationType } from "@microsoft/microsoft-graph-types"; + +/** + * Operations + */ +@defaultPath("operations") +export class _Operations extends _GraphCollection {} +export interface IOperations extends _Operations { } +export const Operations = graphInvokableFactory(_Operations); diff --git a/packages/graph/operations.ts b/packages/graph/ops.ts similarity index 100% rename from packages/graph/operations.ts rename to packages/graph/ops.ts diff --git a/packages/graph/photos/types.ts b/packages/graph/photos/types.ts index 7a2fb2be8..f9e26ca50 100644 --- a/packages/graph/photos/types.ts +++ b/packages/graph/photos/types.ts @@ -2,7 +2,7 @@ import { _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; import { BlobParse, BufferParse } from "@pnp/queryable"; import { Photo as IPhotoType } from "@microsoft/microsoft-graph-types"; import { defaultPath } from "../decorators.js"; -import { graphPatch } from "../operations.js"; +import { graphPatch } from "../ops.js"; @defaultPath("photo") export class _Photo extends _GraphInstance { diff --git a/packages/graph/planner/types.ts b/packages/graph/planner/types.ts index 1f72c34c7..688b92528 100644 --- a/packages/graph/planner/types.ts +++ b/packages/graph/planner/types.ts @@ -9,7 +9,7 @@ import { import { body } from "@pnp/queryable"; import { _GraphInstance, _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; import { getById, IGetById, deleteableWithETag, IDeleteableWithETag, updateableWithETag, IUpdateableWithETag } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; /** diff --git a/packages/graph/presets/all.ts b/packages/graph/presets/all.ts index 4c37b799f..641972213 100644 --- a/packages/graph/presets/all.ts +++ b/packages/graph/presets/all.ts @@ -9,8 +9,9 @@ import "../insights/index.js"; import "../invitations/index.js"; import "../members/index.js"; import "../messages/index.js"; -import "../onedrive/index.js"; +import "../files/index.js"; import "../onenote/index.js"; +import "../operations/index.js"; import "../photos/index.js"; import "../planner/index.js"; import "../search/index.js"; @@ -30,8 +31,9 @@ export * from "../insights/index.js"; export * from "../invitations/index.js"; export * from "../members/index.js"; export * from "../messages/index.js"; -export * from "../onedrive/index.js"; +export * from "../files/index.js"; export * from "../onenote/index.js"; +export * from "../operations/index.js"; export * from "../photos/index.js"; export * from "../planner/index.js"; export * from "../search/index.js"; diff --git a/packages/graph/search/types.ts b/packages/graph/search/types.ts index e65b0c540..11755a119 100644 --- a/packages/graph/search/types.ts +++ b/packages/graph/search/types.ts @@ -2,7 +2,7 @@ import { SearchRequest as ISearchRequestType, SearchResponse as ISearchResponseT import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; import { GraphInit, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; /** * Search diff --git a/packages/graph/shares/types.ts b/packages/graph/shares/types.ts index 52554e2d5..10083be78 100644 --- a/packages/graph/shares/types.ts +++ b/packages/graph/shares/types.ts @@ -1,7 +1,7 @@ import { defaultPath } from "../decorators.js"; import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js"; import { SharedDriveItem as ISharedDriveItem } from "@microsoft/microsoft-graph-types"; -import { DriveItem, IDriveItem } from "../onedrive/types.js"; +import { DriveItem, IDriveItem } from "../files/types.js"; /** * Shares diff --git a/packages/graph/sites/index.ts b/packages/graph/sites/index.ts index a6298e0f2..7ef19395a 100644 --- a/packages/graph/sites/index.ts +++ b/packages/graph/sites/index.ts @@ -2,6 +2,7 @@ import { GraphFI } from "../fi.js"; import { Sites, ISites } from "./types.js"; import "./group.js"; +import "./user.js"; export { ISites, diff --git a/packages/graph/sites/types.ts b/packages/graph/sites/types.ts index 78f60dcab..c649f2c00 100644 --- a/packages/graph/sites/types.ts +++ b/packages/graph/sites/types.ts @@ -1,6 +1,9 @@ +import { combine } from "@pnp/core"; import { defaultPath } from "../decorators.js"; import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js"; import { Site as ISiteType } from "@microsoft/microsoft-graph-types"; +import { graphPost } from "../ops.js"; +import { body } from "@pnp/queryable"; /** * Sites @@ -24,8 +27,18 @@ export class _Sites extends _GraphCollection { * @param siteUrl: string, the server relative url of the site e.g. "/sites/teamsite1" * @returns ISite */ - public getByUrl(hostname: string, siteUrl: string): ISite { - return Site(this, `${hostname}:${siteUrl}:`); + public async getByUrl(hostname: string, siteUrl: string): Promise { + + return Site(this, `${hostname}:${combine("/", siteUrl)}:`).rebase(); + } + + /** + * List sites across geographies in an organization. This API can also be used to enumerate all sites in a non-multi-geo tenant. + * + * @returns A ISites collection which can be used with async iteration to page through the collection + */ + public getAllSites(): ISites { + return Sites(this, "getAllSites"); } } export interface ISites extends _Sites { } @@ -39,7 +52,46 @@ export class _Site extends _GraphInstance { public get sites(): ISites { return Sites(this); } + + /** + * Rebases this ISite instances to ensure it is of the pattern /sites/{site id} regardless of how it was first retrieved + */ + public async rebase(): Promise { + const siteInfo = await Site(this).select("id")(); + return Site([this, `sites/${siteInfo.id}`]); + } } export interface ISite extends _Site { } export const Site = graphInvokableFactory(_Site); +/** + * Followed Sites + * + * Note: At this time listing a user's followed sites is not supported with app-only permissions + */ +@defaultPath("followedsites") +export class _FollowedSites extends _GraphCollection { + + /** + * Adds site(s) to the user's collection of followed sites + * + * @param siteIds The collection of site ids to add + * @returns Site info for the newly followed sites + */ + public add(...siteIds: string[]): Promise { + + return graphPost(FollowedSites(this, "add"), body({ value: siteIds.map(id => ({ id })) })); + } + + /** + * REmoves site(s) to the user's collection of followed sites + * + * @param siteIds The collection of site ids to remove + */ + public remove(...siteIds: string[]): Promise { + + return graphPost(FollowedSites(this, "remove"), body({ value: siteIds.map(id => ({ id })) })); + } +} +export interface IFollowedSites extends _FollowedSites { } +export const FollowedSites = graphInvokableFactory(_FollowedSites); diff --git a/packages/graph/sites/user.ts b/packages/graph/sites/user.ts new file mode 100644 index 000000000..12b4e6426 --- /dev/null +++ b/packages/graph/sites/user.ts @@ -0,0 +1,14 @@ +import { addProp } from "@pnp/queryable"; +import { _User } from "../users/types.js"; +import { IFollowedSites, FollowedSites } from "./types.js"; + +declare module "../users/types" { + interface _User { + followedSites: IFollowedSites; + } + interface IUser { + followedSites: IFollowedSites; + } +} + +addProp(_User, "followedSites", FollowedSites); diff --git a/packages/graph/subscriptions/types.ts b/packages/graph/subscriptions/types.ts index 42849fcc4..067a05a05 100644 --- a/packages/graph/subscriptions/types.ts +++ b/packages/graph/subscriptions/types.ts @@ -2,7 +2,7 @@ import { _GraphInstance, _GraphCollection, graphInvokableFactory } from "../grap import { body } from "@pnp/queryable"; import { Subscription as ISubscriptionType } from "@microsoft/microsoft-graph-types"; import { defaultPath, deleteable, IDeleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; /** * Subscription diff --git a/packages/graph/teams/index.ts b/packages/graph/teams/index.ts index 8bfb28420..0b92df464 100644 --- a/packages/graph/teams/index.ts +++ b/packages/graph/teams/index.ts @@ -3,7 +3,7 @@ import { GraphFI } from "../fi.js"; import { _Group, Group } from "../groups/types.js"; import { ITeamCreateResult, ITeam, Team, ITeams, Teams } from "./types.js"; import { Team as ITeamType } from "@microsoft/microsoft-graph-types"; -import { graphPut } from "../operations.js"; +import { graphPut } from "../ops.js"; import "./users.js"; diff --git a/packages/graph/teams/types.ts b/packages/graph/teams/types.ts index c6c53acc5..d42b2fb89 100644 --- a/packages/graph/teams/types.ts +++ b/packages/graph/teams/types.ts @@ -1,7 +1,7 @@ import { _GraphInstance, _GraphCollection, graphInvokableFactory, GraphInstance } from "../graphqueryable.js"; import { body, HeaderParse } from "@pnp/queryable"; import { updateable, IUpdateable, getById, IGetById, deleteable, IDeleteable } from "../decorators.js"; -import { graphPost } from "../operations.js"; +import { graphPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; import { Team as ITeamType, diff --git a/packages/sp/appcatalog/types.ts b/packages/sp/appcatalog/types.ts index 4cb8386d1..ce5f34157 100644 --- a/packages/sp/appcatalog/types.ts +++ b/packages/sp/appcatalog/types.ts @@ -5,7 +5,7 @@ import { ISPQueryable, SPCollection, } from "../spqueryable.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { File, IFile } from "../files/types.js"; diff --git a/packages/sp/attachments/types.ts b/packages/sp/attachments/types.ts index 048f6d051..46b48ab9a 100644 --- a/packages/sp/attachments/types.ts +++ b/packages/sp/attachments/types.ts @@ -1,7 +1,7 @@ import { headers } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; import { ReadableFile } from "../files/readable-file.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { encodePath } from "../utils/encode-path-str.js"; import { IDeleteableWithETag, diff --git a/packages/sp/batching.ts b/packages/sp/batching.ts index bad455769..172133abc 100644 --- a/packages/sp/batching.ts +++ b/packages/sp/batching.ts @@ -1,6 +1,6 @@ import { getGUID, isUrlAbsolute, combine, CopyFrom, TimelinePipe, isFunc, hOP } from "@pnp/core"; import { parseBinderWithErrorCheck, Queryable } from "@pnp/queryable"; -import { spPost } from "./operations.js"; +import { spPost } from "./ops.js"; import { ISPQueryable, _SPQueryable } from "./spqueryable.js"; import { spfi, SPFI } from "./fi.js"; import { Web, IWeb, _Web } from "./webs/types.js"; diff --git a/packages/sp/behaviors/request-digest.ts b/packages/sp/behaviors/request-digest.ts index 4bbf74d0e..0f5455984 100644 --- a/packages/sp/behaviors/request-digest.ts +++ b/packages/sp/behaviors/request-digest.ts @@ -2,7 +2,7 @@ import { combine, dateAdd, hOP, isFunc, objectDefinedNotNull, TimelinePipe } fro import { JSONParse, Queryable } from "@pnp/queryable"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { ISPQueryable, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { BatchNever } from "../batching.js"; interface IDigestInfo { diff --git a/packages/sp/clientside-pages/types.ts b/packages/sp/clientside-pages/types.ts index ae6bf4eaf..71880a408 100644 --- a/packages/sp/clientside-pages/types.ts +++ b/packages/sp/clientside-pages/types.ts @@ -8,7 +8,7 @@ import { odataUrlFrom } from "../utils/odata-url-from.js"; import { Web, IWeb } from "../webs/types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { Site } from "../sites/types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { getNextOrder, reindex } from "./funcs.js"; import "../files/web.js"; import "../comments/item.js"; diff --git a/packages/sp/clientside-pages/web.ts b/packages/sp/clientside-pages/web.ts index fe5502fe8..8487e65e9 100644 --- a/packages/sp/clientside-pages/web.ts +++ b/packages/sp/clientside-pages/web.ts @@ -10,7 +10,7 @@ import { ClientsideWebpart, } from "./types.js"; import { SPCollection, SPInstance } from "../spqueryable.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { extractWebUrl } from "@pnp/sp"; diff --git a/packages/sp/column-defaults/list.ts b/packages/sp/column-defaults/list.ts index af4a283a7..6c60d6bbc 100644 --- a/packages/sp/column-defaults/list.ts +++ b/packages/sp/column-defaults/list.ts @@ -4,7 +4,7 @@ import { Folder } from "../folders/types.js"; import { IFieldDefault } from "./types.js"; import { IResourcePath } from "../utils/to-resource-path.js"; import { combine, isArray } from "@pnp/core"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { SPCollection } from "../presets/all.js"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/comments/clientside-page.ts b/packages/sp/comments/clientside-page.ts index c84504cdb..0d836eefc 100644 --- a/packages/sp/comments/clientside-page.ts +++ b/packages/sp/comments/clientside-page.ts @@ -1,7 +1,7 @@ import { _ClientsidePage } from "../clientside-pages/types.js"; import { ICommentInfo, IComment, ILikedByInformation } from "./types.js"; import { IItemUpdateResult, Item } from "../items/index.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { SPQueryable } from "../spqueryable.js"; declare module "../clientside-pages/types" { diff --git a/packages/sp/comments/item.ts b/packages/sp/comments/item.ts index 19ef3e253..b15f0bf2b 100644 --- a/packages/sp/comments/item.ts +++ b/packages/sp/comments/item.ts @@ -1,7 +1,7 @@ import { addProp } from "@pnp/queryable"; import { _Item, Item } from "../items/types.js"; import { Comments, IComments, ILikeData, ILikedByInformation, RatingValues } from "./types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine } from "@pnp/core"; import { SPQueryable } from "../spqueryable.js"; diff --git a/packages/sp/comments/types.ts b/packages/sp/comments/types.ts index b793c6305..2f518ffc6 100644 --- a/packages/sp/comments/types.ts +++ b/packages/sp/comments/types.ts @@ -6,7 +6,7 @@ import { } from "../spqueryable.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { body } from "@pnp/queryable"; -import { spDelete, spPost } from "../operations.js"; +import { spDelete, spPost } from "../ops.js"; @defaultPath("comments") export class _Comments extends _SPCollection { diff --git a/packages/sp/content-types/types.ts b/packages/sp/content-types/types.ts index 76ba1c689..79f7c1e0b 100644 --- a/packages/sp/content-types/types.ts +++ b/packages/sp/content-types/types.ts @@ -9,7 +9,7 @@ import { IDeleteable, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; @defaultPath("contenttypes") export class _ContentTypes extends _SPCollection { diff --git a/packages/sp/context-info/index.ts b/packages/sp/context-info/index.ts index 6b7194a50..5c3383381 100644 --- a/packages/sp/context-info/index.ts +++ b/packages/sp/context-info/index.ts @@ -1,5 +1,5 @@ import { hOP } from "@pnp/core"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { SPQueryable, _SPQueryable } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; diff --git a/packages/sp/favorites/types.ts b/packages/sp/favorites/types.ts index 74ef2507a..c223f8e51 100644 --- a/packages/sp/favorites/types.ts +++ b/packages/sp/favorites/types.ts @@ -1,7 +1,7 @@ import { defaultPath } from "../decorators.js"; import { _SPInstance, spInvokableFactory, _SPCollection, SPInit } from "../spqueryable.js"; import { hOP } from "@pnp/core"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { SharepointIds, ResourceVisualization } from "@microsoft/microsoft-graph-types"; diff --git a/packages/sp/features/types.ts b/packages/sp/features/types.ts index e98fb8abb..9b7cdc64f 100644 --- a/packages/sp/features/types.ts +++ b/packages/sp/features/types.ts @@ -5,7 +5,7 @@ import { spInvokableFactory, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; @defaultPath("features") export class _Features extends _SPCollection { diff --git a/packages/sp/fields/types.ts b/packages/sp/fields/types.ts index 3b801afb6..20476566e 100644 --- a/packages/sp/fields/types.ts +++ b/packages/sp/fields/types.ts @@ -7,7 +7,7 @@ import { IDeleteable, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { metadata } from "../utils/metadata.js"; @defaultPath("fields") diff --git a/packages/sp/files/types.ts b/packages/sp/files/types.ts index e5c9d8026..e94473039 100644 --- a/packages/sp/files/types.ts +++ b/packages/sp/files/types.ts @@ -14,7 +14,7 @@ import { import { Item, IItem } from "../items/index.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spGet } from "../operations.js"; +import { spPost, spGet } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { toResourcePath } from "../utils/to-resource-path.js"; import { ISiteUserProps } from "../site-users/types.js"; diff --git a/packages/sp/folders/types.ts b/packages/sp/folders/types.ts index 323375171..e54b43964 100644 --- a/packages/sp/folders/types.ts +++ b/packages/sp/folders/types.ts @@ -13,7 +13,7 @@ import { import { odataUrlFrom } from "../utils/odata-url-from.js"; import { IItem, Item } from "../items/types.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { toResourcePath, IResourcePath } from "../utils/to-resource-path.js"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/hubsites/site.ts b/packages/sp/hubsites/site.ts index 3cc4647cd..4adb0c379 100644 --- a/packages/sp/hubsites/site.ts +++ b/packages/sp/hubsites/site.ts @@ -1,5 +1,5 @@ import { _Site, Site } from "../sites/types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; declare module "../sites/types" { interface _Site { diff --git a/packages/sp/hubsites/web.ts b/packages/sp/hubsites/web.ts index 4383e0568..34bc7450e 100644 --- a/packages/sp/hubsites/web.ts +++ b/packages/sp/hubsites/web.ts @@ -1,6 +1,6 @@ import { _Web, Web } from "../webs/types.js"; import { IHubSiteWebData } from "./types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; declare module "../webs/types" { interface _Web { diff --git a/packages/sp/index.ts b/packages/sp/index.ts index 484493868..7a5e76e32 100644 --- a/packages/sp/index.ts +++ b/packages/sp/index.ts @@ -2,7 +2,7 @@ export * from "./spqueryable.js"; export * from "./decorators.js"; -export * from "./operations.js"; +export * from "./ops.js"; export { SPFI, diff --git a/packages/sp/items/types.ts b/packages/sp/items/types.ts index 6eb4ef1b2..b39ee2552 100644 --- a/packages/sp/items/types.ts +++ b/packages/sp/items/types.ts @@ -16,7 +16,7 @@ import { IListItemFormUpdateValue, List } from "../lists/types.js"; import { body, headers, parseBinderWithErrorCheck, parseODataJSON } from "@pnp/queryable"; import { IList } from "../lists/index.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { IResourcePath } from "../utils/to-resource-path.js"; /** diff --git a/packages/sp/lists/types.ts b/packages/sp/lists/types.ts index b99334e92..22f55fc06 100644 --- a/packages/sp/lists/types.ts +++ b/packages/sp/lists/types.ts @@ -14,7 +14,7 @@ import { import { IChangeQuery } from "../types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { IBasePermissions } from "../security/types.js"; import { IFieldInfo } from "../fields/types.js"; import { IFormInfo } from "../forms/types.js"; diff --git a/packages/sp/navigation/types.ts b/packages/sp/navigation/types.ts index 5e519b127..62c4e8167 100644 --- a/packages/sp/navigation/types.ts +++ b/packages/sp/navigation/types.ts @@ -9,7 +9,7 @@ import { } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../index.js"; import { combine } from "@pnp/core"; diff --git a/packages/sp/operations.ts b/packages/sp/ops.ts similarity index 100% rename from packages/sp/operations.ts rename to packages/sp/ops.ts diff --git a/packages/sp/profiles/types.ts b/packages/sp/profiles/types.ts index faa0c18b5..7be913395 100644 --- a/packages/sp/profiles/types.ts +++ b/packages/sp/profiles/types.ts @@ -10,7 +10,7 @@ import { import { body } from "@pnp/queryable"; import { PrincipalType, PrincipalSource } from "../types.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { AssignFrom } from "@pnp/core"; export class _Profiles extends _SPInstance { diff --git a/packages/sp/recycle-bin/types.ts b/packages/sp/recycle-bin/types.ts index 632f0950b..29dd2e31d 100644 --- a/packages/sp/recycle-bin/types.ts +++ b/packages/sp/recycle-bin/types.ts @@ -5,7 +5,7 @@ import { _SPInstance, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; /** * Describes a recycle bin item diff --git a/packages/sp/regional-settings/funcs.ts b/packages/sp/regional-settings/funcs.ts index 817a5badb..21fd2799b 100644 --- a/packages/sp/regional-settings/funcs.ts +++ b/packages/sp/regional-settings/funcs.ts @@ -1,5 +1,5 @@ import { _SPQueryable, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; export function getValueForUICultureBinder(propName: string): (this: _SPQueryable, cultureName: string) => Promise { diff --git a/packages/sp/regional-settings/types.ts b/packages/sp/regional-settings/types.ts index b753d65c0..f976e8dbc 100644 --- a/packages/sp/regional-settings/types.ts +++ b/packages/sp/regional-settings/types.ts @@ -6,7 +6,7 @@ import { _SPCollection, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; @defaultPath("regionalsettings") export class _RegionalSettings extends _SPInstance { diff --git a/packages/sp/related-items/types.ts b/packages/sp/related-items/types.ts index 22a6150dd..d89c02a9b 100644 --- a/packages/sp/related-items/types.ts +++ b/packages/sp/related-items/types.ts @@ -1,7 +1,7 @@ import { _SPQueryable, ISPQueryable } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; @defaultPath("_api/SP.RelatedItemManager") diff --git a/packages/sp/search/query.ts b/packages/sp/search/query.ts index 3519faa82..760b1d931 100644 --- a/packages/sp/search/query.ts +++ b/packages/sp/search/query.ts @@ -2,7 +2,7 @@ import { _SPInstance, spInvokableFactory, SPInit } from "../spqueryable.js"; import { getHashCode, hOP, isArray } from "@pnp/core"; import { body, CacheAlways, CacheKey, invokable } from "@pnp/queryable"; import { ISearchQuery, ISearchResponse, ISearchResult, ISearchBuilder, SearchQueryInit } from "./types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; const funcs = new Map([ diff --git a/packages/sp/security/funcs.ts b/packages/sp/security/funcs.ts index e4c59f546..7268df72d 100644 --- a/packages/sp/security/funcs.ts +++ b/packages/sp/security/funcs.ts @@ -1,6 +1,6 @@ import { SecurableQueryable, IBasePermissions, PermissionKind } from "./types.js"; import { SPInstance, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; /** * Gets the effective permissions for the user supplied diff --git a/packages/sp/security/types.ts b/packages/sp/security/types.ts index b6d35accb..5e0b62a49 100644 --- a/packages/sp/security/types.ts +++ b/packages/sp/security/types.ts @@ -11,7 +11,7 @@ import { } from "../spqueryable.js"; import { SiteGroups, ISiteGroups } from "../site-groups/types.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; export type SecurableQueryable = _SPInstance & ISecurableMethods; diff --git a/packages/sp/sharing/funcs.ts b/packages/sp/sharing/funcs.ts index c5ee45949..52ad032a5 100644 --- a/packages/sp/sharing/funcs.ts +++ b/packages/sp/sharing/funcs.ts @@ -18,7 +18,7 @@ import { ISharingEmailData, RoleType, } from "./types.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { RoleDefinitions } from "../security/types.js"; import { emptyGuid } from "../types.js"; diff --git a/packages/sp/sharing/web.ts b/packages/sp/sharing/web.ts index c7720efd9..3d691d4a4 100644 --- a/packages/sp/sharing/web.ts +++ b/packages/sp/sharing/web.ts @@ -4,7 +4,7 @@ import { RoleType } from "./types.js"; import { shareObject } from "./funcs.js"; import { combine } from "@pnp/core"; import { body } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; /** * Extend _Web diff --git a/packages/sp/site-designs/types.ts b/packages/sp/site-designs/types.ts index b38a958cd..609957a9e 100644 --- a/packages/sp/site-designs/types.ts +++ b/packages/sp/site-designs/types.ts @@ -1,7 +1,7 @@ import { ISPQueryable, _SPQueryable } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { headers, body } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { combine, hOP } from "@pnp/core"; diff --git a/packages/sp/site-groups/types.ts b/packages/sp/site-groups/types.ts index ded40e4b2..63000403f 100644 --- a/packages/sp/site-groups/types.ts +++ b/packages/sp/site-groups/types.ts @@ -6,7 +6,7 @@ import { import { SiteUsers, ISiteUsers } from "../site-users/types.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; @defaultPath("sitegroups") export class _SiteGroups extends _SPCollection { diff --git a/packages/sp/site-groups/web.ts b/packages/sp/site-groups/web.ts index ac3c950cb..5b6f8ad04 100644 --- a/packages/sp/site-groups/web.ts +++ b/packages/sp/site-groups/web.ts @@ -1,5 +1,5 @@ import { addProp } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { Web, _Web } from "../webs/types.js"; import { ISiteGroups, SiteGroups, ISiteGroup, SiteGroup } from "./types.js"; import "../security/web.js"; diff --git a/packages/sp/site-scripts/types.ts b/packages/sp/site-scripts/types.ts index f2a199390..a652e178d 100644 --- a/packages/sp/site-scripts/types.ts +++ b/packages/sp/site-scripts/types.ts @@ -1,5 +1,5 @@ import { body } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { ISPQueryable, _SPQueryable } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine } from "@pnp/core"; diff --git a/packages/sp/site-users/types.ts b/packages/sp/site-users/types.ts index 607174e70..ce173197b 100644 --- a/packages/sp/site-users/types.ts +++ b/packages/sp/site-users/types.ts @@ -8,7 +8,7 @@ import { import { SiteGroups, ISiteGroups } from "../site-groups/types.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { PrincipalType } from "../types.js"; @defaultPath("siteusers") diff --git a/packages/sp/site-users/web.ts b/packages/sp/site-users/web.ts index 5273cfce2..8bb0cd0e9 100644 --- a/packages/sp/site-users/web.ts +++ b/packages/sp/site-users/web.ts @@ -2,7 +2,7 @@ import { addProp, body } from "@pnp/queryable"; import { _Web, Web } from "../webs/types.js"; import { ISiteUsers, SiteUsers, ISiteUser, SiteUser, IWebEnsureUserResult } from "./types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; declare module "../webs/types" { interface _Web { diff --git a/packages/sp/sites/types.ts b/packages/sp/sites/types.ts index fa62e3c3b..a7c7997c4 100644 --- a/packages/sp/sites/types.ts +++ b/packages/sp/sites/types.ts @@ -4,7 +4,7 @@ import { Web, IWeb } from "../webs/types.js"; import { combine, hOP, isArray } from "@pnp/core"; import { body, TextParse } from "@pnp/queryable"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPatch, spPost } from "../operations.js"; +import { spPatch, spPost } from "../ops.js"; import { IChangeQuery } from "../types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { emptyGuid } from "../types.js"; diff --git a/packages/sp/social/types.ts b/packages/sp/social/types.ts index 2b04e72db..dcac9231c 100644 --- a/packages/sp/social/types.ts +++ b/packages/sp/social/types.ts @@ -6,7 +6,7 @@ import { import { defaultPath } from "../decorators.js"; import { hOP } from "@pnp/core"; import { body } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; @defaultPath("_api/social.following") export class _Social extends _SPInstance implements ISocial { diff --git a/packages/sp/spqueryable.ts b/packages/sp/spqueryable.ts index e246c3d35..c377f83ed 100644 --- a/packages/sp/spqueryable.ts +++ b/packages/sp/spqueryable.ts @@ -1,6 +1,6 @@ import { combine, isUrlAbsolute, isArray, objectDefinedNotNull, stringIsNullOrEmpty } from "@pnp/core"; import { IInvokable, Queryable, queryableFactory } from "@pnp/queryable"; -import { spPostDelete, spPostDeleteETag } from "./operations.js"; +import { spPostDelete, spPostDeleteETag } from "./ops.js"; export type SPInit = string | ISPQueryable | [ISPQueryable, string]; diff --git a/packages/sp/sputilities/types.ts b/packages/sp/sputilities/types.ts index a524d75da..db1e8c653 100644 --- a/packages/sp/sputilities/types.ts +++ b/packages/sp/sputilities/types.ts @@ -2,7 +2,7 @@ import { body } from "@pnp/queryable"; import { _SPQueryable, spInvokableFactory, ISPQueryable, SPInit } from "../spqueryable.js"; import { IPrincipalInfo, PrincipalType, PrincipalSource } from "../types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; import { combine } from "@pnp/core"; export class _Utilities extends _SPQueryable implements IUtilities { diff --git a/packages/sp/subscriptions/types.ts b/packages/sp/subscriptions/types.ts index 9f2c121c7..4406c30ed 100644 --- a/packages/sp/subscriptions/types.ts +++ b/packages/sp/subscriptions/types.ts @@ -5,7 +5,7 @@ import { } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPatch, spDelete } from "../operations.js"; +import { spPost, spPatch, spDelete } from "../ops.js"; @defaultPath("subscriptions") export class _Subscriptions extends _SPCollection { diff --git a/packages/sp/taxonomy/types.ts b/packages/sp/taxonomy/types.ts index 36b7a3975..ccf2b5024 100644 --- a/packages/sp/taxonomy/types.ts +++ b/packages/sp/taxonomy/types.ts @@ -1,7 +1,7 @@ import { isArray } from "@pnp/core"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spDelete, spPatch, spPost } from "../operations.js"; +import { spDelete, spPatch, spPost } from "../ops.js"; import { _SPInstance, spInvokableFactory, _SPCollection } from "../spqueryable.js"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/user-custom-actions/types.ts b/packages/sp/user-custom-actions/types.ts index e39db3d58..be1f28be7 100644 --- a/packages/sp/user-custom-actions/types.ts +++ b/packages/sp/user-custom-actions/types.ts @@ -7,7 +7,7 @@ import { } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { IBasePermissions } from "../security/index.js"; @defaultPath("usercustomactions") diff --git a/packages/sp/views/types.ts b/packages/sp/views/types.ts index f80665a9f..2ec295a36 100644 --- a/packages/sp/views/types.ts +++ b/packages/sp/views/types.ts @@ -7,7 +7,7 @@ import { IDeleteable, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { encodePath } from "../utils/encode-path-str.js"; @defaultPath("views") diff --git a/packages/sp/webparts/types.ts b/packages/sp/webparts/types.ts index 7c2c54ce7..ac80a2939 100644 --- a/packages/sp/webparts/types.ts +++ b/packages/sp/webparts/types.ts @@ -9,7 +9,7 @@ import { ISPInstance, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; -import { spPost } from "../operations.js"; +import { spPost } from "../ops.js"; export class _LimitedWebPartManager extends _SPQueryable implements ILimitedWebPartManager { diff --git a/packages/sp/webs/types.ts b/packages/sp/webs/types.ts index 3767b35f1..077cb9f6b 100644 --- a/packages/sp/webs/types.ts +++ b/packages/sp/webs/types.ts @@ -15,7 +15,7 @@ import { import { defaultPath } from "../decorators.js"; import { IChangeQuery } from "../types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPost, spPostMerge } from "../operations.js"; +import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine, isArray } from "@pnp/core"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/test/graph/onedrive.ts b/test/graph/onedrive.ts index ec232d2c2..0f6dac4c1 100644 --- a/test/graph/onedrive.ts +++ b/test/graph/onedrive.ts @@ -3,9 +3,9 @@ import * as path from "path"; import * as fs from "fs"; import findupSync from "findup-sync"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import { getRandomString, stringIsNullOrEmpty } from "@pnp/core"; -import { IItemOptions } from "@pnp/graph/onedrive/types"; +import { IItemOptions } from "@pnp/graph/files/types"; // give ourselves a single reference to the projectRoot const projectRoot = path.resolve(path.dirname(findupSync("package.json"))); diff --git a/test/graph/querable.ts b/test/graph/querable.ts index 012d2e8b1..5c1e79bba 100644 --- a/test/graph/querable.ts +++ b/test/graph/querable.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import "@pnp/graph/sites/group"; import "@pnp/graph/users"; -import "@pnp/graph/onedrive"; +import "@pnp/graph/files"; import { Drive, Group } from "@microsoft/microsoft-graph-types"; import { hOP, stringIsNullOrEmpty } from "@pnp/core"; import getValidUser from "./utilities/getValidUser.js"; diff --git a/test/graph/sites.ts b/test/graph/sites.ts index 1cb20258f..b250f0424 100644 --- a/test/graph/sites.ts +++ b/test/graph/sites.ts @@ -30,8 +30,9 @@ describe("Sites", function () { site = await getTestingGraphSPSite(this); const tetssite = await site(); const url = new URL(tetssite.webUrl); - const siteByUrl = await this.pnp.graph.sites.getByUrl(url.hostname, url.pathname)(); - passed = (siteByUrl.webUrl.toLowerCase() === tetssite.webUrl.toLowerCase()); + const siteByUrl = await this.pnp.graph.sites.getByUrl(url.hostname, url.pathname); + const siteInfo = await siteByUrl(); + passed = (siteInfo.webUrl.toLowerCase() === tetssite.webUrl.toLowerCase()); return expect(passed).is.true; }); From d9a50e961aa8f3ceb580ae9b862a6ce5c77a6af9 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Thu, 10 Aug 2023 14:19:43 -0400 Subject: [PATCH 3/5] fixing reused test ids --- test/core/util.ts | 2 +- test/pnp-test.ts | 2 +- test/sp/batch.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/util.ts b/test/core/util.ts index 4a032bfeb..33485f83f 100644 --- a/test/core/util.ts +++ b/test/core/util.ts @@ -92,7 +92,7 @@ describe("isFunc", function () { })).to.be.true; })); - it("False", pnpTest("ff0020e6-0e1b-4b12-a4a1-8a4b2fc8fcdb", function () { + it("False", pnpTest("2a147d36-64ad-4888-a425-e4d18ead4448", function () { // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(isFunc({ val: 0 })).to.be.false; // eslint-disable-next-line @typescript-eslint/no-unused-expressions diff --git a/test/pnp-test.ts b/test/pnp-test.ts index 2fc338275..09ec4f191 100644 --- a/test/pnp-test.ts +++ b/test/pnp-test.ts @@ -51,7 +51,7 @@ function PnPTestIdHeader(id: () => string): TimelinePipe { export function pnpTest(id: string, testFunc: (this: IPnPTestFuncThis) => any): IPnPTestFunc { if (idDupeTracker.indexOf(id.toLowerCase()) > -1) { - throw Error(`Test ${id} is already in use.`); + throw Error(`Test id ${id} is already in use.`); } idDupeTracker.push(id.toLowerCase()); diff --git a/test/sp/batch.ts b/test/sp/batch.ts index f4d2f3e23..9e9c7e636 100644 --- a/test/sp/batch.ts +++ b/test/sp/batch.ts @@ -288,7 +288,7 @@ describe("Batching", function () { expect(p2).to.eventually.be.fulfilled; })); - it("Should rebase objects to allow queries on returned objects", pnpTest("d9535bc2-c59a-49ba-8666-b3d80510aca5", async function () { + it("Should rebase objects to allow queries on returned objects", pnpTest("5e17585b-ce83-4fd0-8392-1132069b5503", async function () { const props = await this.props({ listName: "BatchTestRebase", From 0410436742b7c67140a2ad1658c62e00eee0e032 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Thu, 10 Aug 2023 15:33:53 -0400 Subject: [PATCH 4/5] permissions, some docs fixes --- debug/launch/graph.ts | 22 +++----- debug/launch/main.ts | 4 +- docs/graph/permissions.md | 79 +++++++++++++++++++++++++++++ docs/graph/shares.md | 2 +- docs/graph/users.md | 2 +- mkdocs.yml | 3 +- packages/graph/permissions/index.ts | 8 +++ packages/graph/permissions/site.ts | 14 +++++ packages/graph/permissions/types.ts | 29 +++++++++++ 9 files changed, 144 insertions(+), 19 deletions(-) create mode 100644 docs/graph/permissions.md create mode 100644 packages/graph/permissions/index.ts create mode 100644 packages/graph/permissions/site.ts create mode 100644 packages/graph/permissions/types.ts diff --git a/debug/launch/graph.ts b/debug/launch/graph.ts index 5aa4c6498..9fe04eec9 100644 --- a/debug/launch/graph.ts +++ b/debug/launch/graph.ts @@ -1,26 +1,20 @@ import { Logger, LogLevel } from "@pnp/logging"; import { graphSetup } from "./setup.js"; -import "@pnp/graph/sites"; import "@pnp/graph/users"; -import "@pnp/graph/files"; -import "@pnp/graph/operations"; declare var process: { exit(code?: number): void }; export async function Example(settings: any) { - const graph = graphSetup(settings); + const graph = graphSetup(settings); - const site = await graph.sites.getByUrl("318studios.sharepoint.com", "/sites/dev") + const users = await graph.users(); - const ops = await site.operations(); - + Logger.log({ + data: users, + level: LogLevel.Info, + message: "List of Users Data", + }); - Logger.log({ - data: ops, - level: LogLevel.Info, - message: "List of Users Data", - }); - - process.exit(0); + process.exit(0); } diff --git a/debug/launch/main.ts b/debug/launch/main.ts index 9c9922e07..2a4fdec1e 100644 --- a/debug/launch/main.ts +++ b/debug/launch/main.ts @@ -8,8 +8,8 @@ import { ITestingSettings } from "../../test/load-settings.js"; // add your debugging imports here and prior to submitting a PR git checkout debug/debug.ts // will allow you to keep all your debugging files locally // comment out the example -// import { Example } from "./sp.js"; -import { Example } from "./graph.js"; +import { Example } from "./sp.js"; +// import { Example } from "./graph.js"; // setup the connection to SharePoint using the settings file, you can // override any of the values as you want here, just be sure not to commit diff --git a/docs/graph/permissions.md b/docs/graph/permissions.md new file mode 100644 index 000000000..ade06dc57 --- /dev/null +++ b/docs/graph/permissions.md @@ -0,0 +1,79 @@ +# @pnp/graph/permissions + +Allows you to manipulate the permissions of various entities. + +[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) + +## site permissions + +[![Official Docs](https://img.shields.io/badge/Official_Graph_Docs-social.svg)](https://learn.microsoft.com/en-us/graph/api/resources/permission?view=graph-rest-1.0) + +Allows you to manage application permissions for sites. + +### list site permissions + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/permissions"; + +const graph = graphfi(...); + +const permissions = await graph.sites.getById("{site id}").permissions(); +``` + +### get a site permission + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/permissions"; + +const graph = graphfi(...); + +const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}")(); +``` + +### add a site permission + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/permissions"; + +const graph = graphfi(...); + +const permissions = await graph.sites.getById("{site id}").permissions.add({ + roles: ["fullcontrol"], + grantedToIdentities: [{ + id: "89ea5c94-7736-4e25-95ad-3fa95f62b66e", + displayName: "Contoso Time Manager App", + }], +}); +``` + +### update a site permission + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/permissions"; + +const graph = graphfi(...); + +const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}").update({ + roles: ["read"], +}); +``` + +### delete a site permission + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/sites"; +import "@pnp/graph/permissions"; + +const graph = graphfi(...); + +const permissions = await graph.sites.getById("{site id}").permissions.getById("{permission id}").delete(); +``` diff --git a/docs/graph/shares.md b/docs/graph/shares.md index c2b13040a..fd3bc2060 100644 --- a/docs/graph/shares.md +++ b/docs/graph/shares.md @@ -32,7 +32,7 @@ const shareInfo = await graph.shares.getById(shareLink)(); ## Access a Share's driveItem resource -You can also access the full functionality of the driveItem via a share. Find [more details on the capabilities of driveItem here](./onedrive.md). +You can also access the full functionality of the driveItem via a share. Find [more details on the capabilities of driveItem here](./files.md). ```TS import { graphfi } from "@pnp/graph"; diff --git a/docs/graph/users.md b/docs/graph/users.md index 8b8a0aae2..f863a0c90 100644 --- a/docs/graph/users.md +++ b/docs/graph/users.md @@ -131,4 +131,4 @@ See [Messages](./messages.md) ## User OneDrive -See [OneDrive](./onedrive.md) +See [Files](./files.md) diff --git a/mkdocs.yml b/mkdocs.yml index a0d11c4da..9b00f5691 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -17,7 +17,7 @@ nav: - 'In NodeJS': 'concepts/auth-nodejs.md' - 'Batching': 'concepts/batching.md' - 'Batching & Caching': 'concepts/batching-caching.md' - - 'Calling Other Endpoints': 'concepts/calling-other-endpoints' + - 'Calling Other Endpoints': 'concepts/calling-other-endpoints.md' - 'Custom Bundling': 'concepts/custom-bundle.md' - 'Error-Handling': 'concepts/error-handling.md' - 'Project Config/Services Setup': 'concepts/project-preset.md' @@ -56,6 +56,7 @@ nav: - messages: 'graph/messages.md' - outlook: 'graph/outlook.md' - operations: 'graph/operations.md' + - permissions: 'graph/permissions.md' - photos: 'graph/photos.md' - planner: 'graph/planner.md' - search: 'graph/search.md' diff --git a/packages/graph/permissions/index.ts b/packages/graph/permissions/index.ts new file mode 100644 index 000000000..44f0a05ee --- /dev/null +++ b/packages/graph/permissions/index.ts @@ -0,0 +1,8 @@ +import "./site.js"; + +export { + IPermission, + IPermissions, + Permission, + Permissions, +} from "./types.js"; diff --git a/packages/graph/permissions/site.ts b/packages/graph/permissions/site.ts new file mode 100644 index 000000000..a293c6e24 --- /dev/null +++ b/packages/graph/permissions/site.ts @@ -0,0 +1,14 @@ +import { addProp } from "@pnp/queryable"; +import { _Site } from "../sites/types.js"; +import { IPermissions, Permissions } from "./types.js"; + +declare module "../sites/types" { + interface _Site { + readonly permissions: IPermissions; + } + interface ISite { + readonly permissions: IPermissions; + } +} + +addProp(_Site, "permissions", Permissions); diff --git a/packages/graph/permissions/types.ts b/packages/graph/permissions/types.ts new file mode 100644 index 000000000..518236bf4 --- /dev/null +++ b/packages/graph/permissions/types.ts @@ -0,0 +1,29 @@ +import { body } from "@pnp/queryable"; +import { IDeleteable, IGetById, IUpdateable, defaultPath, deleteable, getById, updateable } from "../decorators.js"; +import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js"; +import { Permission as IPermissionType } from "@microsoft/microsoft-graph-types"; +import { graphPost } from "../ops.js"; + +/** + * Permission + */ +@deleteable() +@updateable() +export class _Permission extends _GraphInstance {} +export interface IPermission extends _Permission, IUpdateable>, IDeleteable { } +export const Permission = graphInvokableFactory(_Permission); + +/** + * Permissions + */ +@defaultPath("permissions") +@getById(Permission) +export class _Permissions extends _GraphCollection { + + public add(permissions: Pick): Promise { + + return graphPost(this, body(permissions)); + } +} +export interface IPermissions extends _Permissions, IGetById { } +export const Permissions = graphInvokableFactory(_Permissions); From b6cf032e89f0513ac266169b35ceee11817e9c28 Mon Sep 17 00:00:00 2001 From: Patrick Rodgers Date: Thu, 10 Aug 2023 20:53:41 -0400 Subject: [PATCH 5/5] moving operations.ts in sp & graph into respective *queryable files --- CHANGELOG.md | 4 +-- packages/graph/attachments/types.ts | 3 +- packages/graph/batching.ts | 3 +- packages/graph/bookings/types.ts | 3 +- packages/graph/calendars/types.ts | 3 +- packages/graph/cloud-communications/types.ts | 3 +- packages/graph/columns/addColumns.ts | 4 +-- packages/graph/columns/content-types.ts | 2 +- packages/graph/contacts/types.ts | 3 +- packages/graph/content-types/lists.ts | 5 ++- packages/graph/content-types/sites.ts | 5 ++- packages/graph/content-types/types.ts | 3 +- packages/graph/conversations/types.ts | 3 +- packages/graph/decorators.ts | 3 +- packages/graph/directory-objects/types.ts | 3 +- packages/graph/files/funcs.ts | 2 +- packages/graph/files/types.ts | 4 ++- packages/graph/files/users.ts | 2 +- packages/graph/graphqueryable.ts | 30 ++++++++++++----- packages/graph/groups/types.ts | 3 +- packages/graph/index.ts | 12 +------ packages/graph/invitations/types.ts | 3 +- packages/graph/lists/types.ts | 3 +- packages/graph/members/types.ts | 3 +- packages/graph/messages/users.ts | 2 +- packages/graph/onenote/types.ts | 2 +- packages/graph/ops.ts | 22 ------------- packages/graph/permissions/types.ts | 3 +- packages/graph/photos/types.ts | 3 +- packages/graph/planner/types.ts | 3 +- packages/graph/search/types.ts | 3 +- packages/graph/sites/types.ts | 3 +- packages/graph/subscriptions/types.ts | 3 +- packages/graph/teams/index.ts | 2 +- packages/graph/teams/types.ts | 3 +- packages/sp/appcatalog/types.ts | 2 +- packages/sp/attachments/types.ts | 2 +- packages/sp/batching.ts | 3 +- packages/sp/behaviors/request-digest.ts | 3 +- packages/sp/clientside-pages/types.ts | 3 +- packages/sp/clientside-pages/web.ts | 3 +- packages/sp/column-defaults/list.ts | 2 +- packages/sp/comments/clientside-page.ts | 3 +- packages/sp/comments/item.ts | 3 +- packages/sp/comments/types.ts | 3 +- packages/sp/content-types/types.ts | 3 +- packages/sp/context-info/index.ts | 3 +- packages/sp/favorites/types.ts | 3 +- packages/sp/features/types.ts | 2 +- packages/sp/fields/types.ts | 3 +- packages/sp/files/types.ts | 3 +- packages/sp/folders/types.ts | 3 +- packages/sp/groupsitemanager/types.ts | 3 +- packages/sp/hubsites/site.ts | 2 +- packages/sp/hubsites/web.ts | 2 +- packages/sp/index.ts | 2 -- packages/sp/items/types.ts | 2 +- packages/sp/lists/types.ts | 3 +- packages/sp/navigation/types.ts | 3 +- packages/sp/ops.ts | 33 ------------------- packages/sp/profiles/types.ts | 2 +- packages/sp/recycle-bin/types.ts | 2 +- packages/sp/regional-settings/funcs.ts | 3 +- packages/sp/regional-settings/types.ts | 2 +- packages/sp/related-items/types.ts | 3 +- packages/sp/search/query.ts | 3 +- packages/sp/security/funcs.ts | 3 +- packages/sp/security/types.ts | 3 +- packages/sp/sharing/funcs.ts | 3 +- packages/sp/sharing/web.ts | 2 +- packages/sp/site-designs/types.ts | 4 +-- packages/sp/site-groups/types.ts | 3 +- packages/sp/site-groups/web.ts | 2 +- packages/sp/site-scripts/types.ts | 3 +- packages/sp/site-users/types.ts | 3 +- packages/sp/site-users/web.ts | 2 +- packages/sp/sites/types.ts | 3 +- packages/sp/social/types.ts | 2 +- packages/sp/spqueryable.ts | 34 ++++++++++++++++++-- packages/sp/sputilities/types.ts | 3 +- packages/sp/subscriptions/types.ts | 4 ++- packages/sp/taxonomy/types.ts | 3 +- packages/sp/user-custom-actions/types.ts | 3 +- packages/sp/views/types.ts | 3 +- packages/sp/webparts/types.ts | 2 +- packages/sp/webs/types.ts | 3 +- 86 files changed, 158 insertions(+), 203 deletions(-) delete mode 100644 packages/graph/ops.ts delete mode 100644 packages/sp/ops.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b0901d7..49c69bd16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,12 +28,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - graph - paged method removed from IGraphQueryableCollection + - ./operations.ts methods moved to ./graphqueryable.ts - sp - getPaged method removed from _Items/IItems - PagedItemCollection removed from library - removed /items/get-all import, unneeded, use async iterator patterns - - operations.ts renamed to ops.ts + - ./operations.ts methods moved to ./spqueryable.ts ### Changed @@ -43,7 +44,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - All GraphQueryable*, _GraphQueryable*, and IGraphQueryable* have been renamed to remove "Queryable" (ex: GraphQueryableCollection is now GraphCollection) - @pnp/graph/onedrive renamed to @pnp/graph/files - ISites.getByUrl is now async - - operations.ts renamed to ops.ts - sp - _Items and IItems now supports async iterator pattern diff --git a/packages/graph/attachments/types.ts b/packages/graph/attachments/types.ts index 781377439..2818fd31f 100644 --- a/packages/graph/attachments/types.ts +++ b/packages/graph/attachments/types.ts @@ -1,7 +1,6 @@ import { Attachment as IAttachmentType } from "@microsoft/microsoft-graph-types"; import { body } from "@pnp/queryable"; -import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; -import { graphPost } from "../ops.js"; +import { _GraphCollection, _GraphInstance, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; import { type } from "../utils/type.js"; diff --git a/packages/graph/batching.ts b/packages/graph/batching.ts index 6dd53cfa4..dcfa6fb7a 100644 --- a/packages/graph/batching.ts +++ b/packages/graph/batching.ts @@ -1,7 +1,6 @@ import { isUrlAbsolute, hOP, TimelinePipe, getGUID, CopyFrom, objectDefinedNotNull, isFunc, combine } from "@pnp/core"; import { parseBinderWithErrorCheck, Queryable, body, InjectHeaders } from "@pnp/queryable"; -import { IGraphQueryable, _GraphQueryable } from "./graphqueryable.js"; -import { graphPost } from "./ops.js"; +import { IGraphQueryable, _GraphQueryable, graphPost } from "./graphqueryable.js"; import { GraphFI } from "./fi.js"; declare module "./fi" { diff --git a/packages/graph/bookings/types.ts b/packages/graph/bookings/types.ts index 4563ed14c..bcb323e94 100644 --- a/packages/graph/bookings/types.ts +++ b/packages/graph/bookings/types.ts @@ -7,9 +7,8 @@ import { BookingCurrency as IBookingCurrencyEntity, BookingCustomQuestion as IBookingCustomQuestionEntity, } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { calendarView } from "./funcs.js"; diff --git a/packages/graph/calendars/types.ts b/packages/graph/calendars/types.ts index 049eb417c..9dd39a608 100644 --- a/packages/graph/calendars/types.ts +++ b/packages/graph/calendars/types.ts @@ -1,8 +1,7 @@ import { body } from "@pnp/queryable"; import { Event as IEventType, Calendar as ICalendarType } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphCollection, _GraphInstance, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { defaultPath, IDeleteable, deleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { calendarView, instances } from "./funcs.js"; /** diff --git a/packages/graph/cloud-communications/types.ts b/packages/graph/cloud-communications/types.ts index c714db00f..19684f18a 100644 --- a/packages/graph/cloud-communications/types.ts +++ b/packages/graph/cloud-communications/types.ts @@ -1,8 +1,7 @@ import { Presence as IUserPresence } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js"; import { defaultPath } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/columns/addColumns.ts b/packages/graph/columns/addColumns.ts index 924944d38..8edb6a224 100644 --- a/packages/graph/columns/addColumns.ts +++ b/packages/graph/columns/addColumns.ts @@ -1,5 +1,5 @@ -import { IColumn } from "./types"; -import { graphPost } from "../ops.js"; +import { IColumn } from "./types.js"; +import { graphPost } from "../graphqueryable.js"; import { body } from "@pnp/queryable"; import { ColumnDefinition as IColumnDefinition, diff --git a/packages/graph/columns/content-types.ts b/packages/graph/columns/content-types.ts index 3c0e4c1cf..b6d094ed9 100644 --- a/packages/graph/columns/content-types.ts +++ b/packages/graph/columns/content-types.ts @@ -1,5 +1,5 @@ import { addProp, body } from "@pnp/queryable"; -import { graphPost } from "../ops.js"; +import { graphPost } from "../graphqueryable.js"; import { _ContentType } from "../content-types/types.js"; import { Columns, IColumns,IColumn, _Columns } from "./types.js"; import { IColumnAddResult } from "./addColumns.js"; diff --git a/packages/graph/contacts/types.ts b/packages/graph/contacts/types.ts index a73e662f9..b8d14e20b 100644 --- a/packages/graph/contacts/types.ts +++ b/packages/graph/contacts/types.ts @@ -1,7 +1,6 @@ -import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphCollection, _GraphInstance, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { Contact as IContactType, ContactFolder as IContactFolderType, EmailAddress as IEmailAddressType } from "@microsoft/microsoft-graph-types"; import { defaultPath, updateable, deleteable, IUpdateable, IDeleteable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/content-types/lists.ts b/packages/graph/content-types/lists.ts index 5d8a5b026..ff924d19a 100644 --- a/packages/graph/content-types/lists.ts +++ b/packages/graph/content-types/lists.ts @@ -1,8 +1,7 @@ -import { addProp } from "@pnp/queryable"; -import { graphPost } from "../ops.js"; +import { addProp, body} from "@pnp/queryable"; +import { graphPost } from "../graphqueryable.js"; import { _List } from "../lists/types.js"; import { ContentTypes, IContentType, IContentTypeAddResult, IContentTypes, _ContentTypes } from "./types.js"; -import { body } from "@pnp/queryable"; declare module "../lists/types" { interface _List { diff --git a/packages/graph/content-types/sites.ts b/packages/graph/content-types/sites.ts index 015b0f683..2da9d9378 100644 --- a/packages/graph/content-types/sites.ts +++ b/packages/graph/content-types/sites.ts @@ -1,9 +1,8 @@ -import { addProp } from "@pnp/queryable"; +import { addProp, body } from "@pnp/queryable"; import { ContentType as IContentTypeEntity, } from "@microsoft/microsoft-graph-types"; -import { graphGet, graphPost } from "../ops.js"; -import { body } from "@pnp/queryable"; +import { graphGet, graphPost } from "../graphqueryable.js"; import { Site, _Site } from "../sites/types.js"; import { ContentTypes, IContentType, IContentTypeAddResult, IContentTypes, _ContentTypes } from "./types.js"; diff --git a/packages/graph/content-types/types.ts b/packages/graph/content-types/types.ts index 1477519b7..d0e524b37 100644 --- a/packages/graph/content-types/types.ts +++ b/packages/graph/content-types/types.ts @@ -2,9 +2,8 @@ import { ContentType as IContentTypeEntity, ItemReference as IItemReference, } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphGet, graphPost } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphGet, graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { JSONHeaderParse } from "@pnp/queryable"; diff --git a/packages/graph/conversations/types.ts b/packages/graph/conversations/types.ts index 2a808f50b..e536fa8b8 100644 --- a/packages/graph/conversations/types.ts +++ b/packages/graph/conversations/types.ts @@ -10,9 +10,10 @@ import { _GraphCollection, _GraphInstance, graphInvokableFactory, + graphPost, + graphDelete, } from "../graphqueryable.js"; import { defaultPath, updateable, IUpdateable, deleteable, IDeleteable, addable, IAddable, getById, IGetById } from "../decorators.js"; -import { graphPost, graphDelete } from "../ops.js"; /** * Conversation diff --git a/packages/graph/decorators.ts b/packages/graph/decorators.ts index c56e8a951..f1b42a861 100644 --- a/packages/graph/decorators.ts +++ b/packages/graph/decorators.ts @@ -1,5 +1,4 @@ -import { IGraphQueryable } from "./graphqueryable.js"; -import { graphDelete, graphPatch, graphPost } from "./ops.js"; +import { IGraphQueryable, graphDelete, graphPatch, graphPost } from "./graphqueryable.js"; import { body, headers } from "@pnp/queryable"; /** diff --git a/packages/graph/directory-objects/types.ts b/packages/graph/directory-objects/types.ts index e266c8dac..bd8270102 100644 --- a/packages/graph/directory-objects/types.ts +++ b/packages/graph/directory-objects/types.ts @@ -1,8 +1,7 @@ -import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphCollection, _GraphInstance, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { DirectoryObject as IDirectoryObjectType } from "@microsoft/microsoft-graph-types"; import { defaultPath, getById, IGetById, deleteable, IDeleteable } from "../decorators.js"; import { body } from "@pnp/queryable"; -import { graphPost } from "../ops.js"; import { Count } from "../behaviors/paged.js"; /** diff --git a/packages/graph/files/funcs.ts b/packages/graph/files/funcs.ts index 0d5af81fa..34c46f260 100644 --- a/packages/graph/files/funcs.ts +++ b/packages/graph/files/funcs.ts @@ -1,6 +1,6 @@ import { combine } from "@pnp/core"; import { body, InjectHeaders } from "@pnp/queryable"; -import { graphPost, graphPut } from "../ops.js"; +import { graphPost, graphPut } from "../graphqueryable.js"; import { DriveItem, IDriveItemAddResult, IFileOptions } from "./types.js"; export interface ICheckInOptions { diff --git a/packages/graph/files/types.ts b/packages/graph/files/types.ts index e145006a9..bea36b02f 100644 --- a/packages/graph/files/types.ts +++ b/packages/graph/files/types.ts @@ -7,12 +7,14 @@ import { _GraphCollection, graphInvokableFactory, GraphQueryable, + graphPatch, + graphPost, + graphPut, } from "../graphqueryable.js"; import { Drive as IDriveType, DriveItem as IDriveItemType, ItemPreviewInfo as IDriveItemPreviewInfo, ItemAnalytics as IItemAnalytics } 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"; -import { graphPatch, graphPost, graphPut } from "../ops.js"; import { driveItemUpload } from "./funcs.js"; /** diff --git a/packages/graph/files/users.ts b/packages/graph/files/users.ts index d144214a1..bbb4fd651 100644 --- a/packages/graph/files/users.ts +++ b/packages/graph/files/users.ts @@ -1,5 +1,5 @@ import { addProp, body } from "@pnp/queryable"; -import { graphPost } from "../ops.js"; +import { graphPost } from "../graphqueryable.js"; import { _User } from "../users/types.js"; import { IDrive, Drive, IDrives, Drives, _Drive, DriveItem, IDriveItem, _DriveItem, IItemOptions } from "./types.js"; diff --git a/packages/graph/graphqueryable.ts b/packages/graph/graphqueryable.ts index 2f9ef4613..f2e221d42 100644 --- a/packages/graph/graphqueryable.ts +++ b/packages/graph/graphqueryable.ts @@ -1,7 +1,7 @@ import { isArray, objectDefinedNotNull } from "@pnp/core"; -import { IInvokable, Queryable, queryableFactory } from "@pnp/queryable"; +import { IInvokable, Queryable, queryableFactory, op, get, post, patch, del, put } from "@pnp/queryable"; import { ConsistencyLevel } from "./behaviors/consistency-level.js"; -import { Paged } from "./behaviors/paged.js"; +import { IPagedResult, Paged } from "./behaviors/paged.js"; export type GraphInit = string | IGraphQueryable | [IGraphQueryable, string]; @@ -220,9 +220,23 @@ export class _GraphInstance extends _GraphQueryable { } export interface IGraphInstance extends IInvokable, IGraphQueryable { } export const GraphInstance = graphInvokableFactory(_GraphInstance); -export interface IPagedResult { - count: number; - value: any | any[] | null; - hasNext: boolean; - nextLink: string; -} +export const graphGet = (o: IGraphQueryable, init?: RequestInit): Promise => { + return op(o, get, init); +}; + +export const graphPost = (o: IGraphQueryable, init?: RequestInit): Promise => { + return op(o, post, init); +}; + +export const graphDelete = (o: IGraphQueryable, init?: RequestInit): Promise => { + return op(o, del, init); +}; + +export const graphPatch = (o: IGraphQueryable, init?: RequestInit): Promise => { + return op(o, patch, init); +}; + +export const graphPut = (o: IGraphQueryable, init?: RequestInit): Promise => { + return op(o, put, init); +}; + diff --git a/packages/graph/groups/types.ts b/packages/graph/groups/types.ts index 8926cf71d..f8d7810af 100644 --- a/packages/graph/groups/types.ts +++ b/packages/graph/groups/types.ts @@ -1,8 +1,7 @@ import { Event as IEventType, Group as IGroupType } from "@microsoft/microsoft-graph-types"; import { body } from "@pnp/queryable"; -import { graphInvokableFactory } from "../graphqueryable.js"; +import { graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { _DirectoryObject, _DirectoryObjects } from "../directory-objects/types.js"; export enum GroupType { diff --git a/packages/graph/index.ts b/packages/graph/index.ts index 50ee4be80..61ea18fd6 100644 --- a/packages/graph/index.ts +++ b/packages/graph/index.ts @@ -1,16 +1,6 @@ export { graphfi as graphfi, GraphFI as GraphFI } from "./fi.js"; -export { - IGraphCollection, - IGraphInstance, - GraphQueryable, - IGraphQueryable, - GraphCollection, - GraphInstance, - IGraphConstructor, -} from "./graphqueryable.js"; - -export * from "./ops.js"; +export * from "./graphqueryable.js"; export * from "./behaviors/consistency-level.js"; export * from "./behaviors/defaults.js"; diff --git a/packages/graph/invitations/types.ts b/packages/graph/invitations/types.ts index 959fad8b0..7907733f5 100644 --- a/packages/graph/invitations/types.ts +++ b/packages/graph/invitations/types.ts @@ -1,8 +1,7 @@ import { body } from "@pnp/queryable"; import { Invitation as IInvitationType } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphCollection, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { defaultPath } from "../decorators.js"; -import { graphPost } from "../ops.js"; /** * Invitations diff --git a/packages/graph/lists/types.ts b/packages/graph/lists/types.ts index 209797538..4f623dd2c 100644 --- a/packages/graph/lists/types.ts +++ b/packages/graph/lists/types.ts @@ -1,7 +1,6 @@ import { List as IListEntity } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; +import { _GraphCollection, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js"; import { defaultPath, deleteable, IDeleteable, updateable, IUpdateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/members/types.ts b/packages/graph/members/types.ts index e531aaa34..19a56d72d 100644 --- a/packages/graph/members/types.ts +++ b/packages/graph/members/types.ts @@ -1,8 +1,7 @@ import { body } from "@pnp/queryable"; import { User as IMemberType } from "@microsoft/microsoft-graph-types"; -import { _GraphCollection, _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphCollection, _GraphInstance, graphInvokableFactory, graphDelete, graphPost } from "../graphqueryable.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; -import { graphDelete, graphPost } from "../ops.js"; /** * Member diff --git a/packages/graph/messages/users.ts b/packages/graph/messages/users.ts index 44cd0f8a5..281280c35 100644 --- a/packages/graph/messages/users.ts +++ b/packages/graph/messages/users.ts @@ -1,7 +1,7 @@ import { addProp, body } from "@pnp/queryable"; import { _User, User } from "../users/types.js"; import { IMessages, Messages, IMailboxSettings, MailboxSettings, IMailFolders, MailFolders, IMessage } from "./types.js"; -import { graphPost } from "../ops.js"; +import { graphPost } from "../graphqueryable.js"; declare module "../users/types" { interface _User { diff --git a/packages/graph/onenote/types.ts b/packages/graph/onenote/types.ts index 03b501d6c..491041a7c 100644 --- a/packages/graph/onenote/types.ts +++ b/packages/graph/onenote/types.ts @@ -6,9 +6,9 @@ import { _GraphCollection, IGraphCollection, graphInvokableFactory, + graphPost, } from "../graphqueryable.js"; import { defaultPath, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; /** * Represents a onenote entity diff --git a/packages/graph/ops.ts b/packages/graph/ops.ts deleted file mode 100644 index d7c19f307..000000000 --- a/packages/graph/ops.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { op, get, post, patch, del, put } from "@pnp/queryable"; -import { IGraphQueryable } from "./graphqueryable.js"; - -export const graphGet = (o: IGraphQueryable, init?: RequestInit): Promise => { - return op(o, get, init); -}; - -export const graphPost = (o: IGraphQueryable, init?: RequestInit): Promise => { - return op(o, post, init); -}; - -export const graphDelete = (o: IGraphQueryable, init?: RequestInit): Promise => { - return op(o, del, init); -}; - -export const graphPatch = (o: IGraphQueryable, init?: RequestInit): Promise => { - return op(o, patch, init); -}; - -export const graphPut = (o: IGraphQueryable, init?: RequestInit): Promise => { - return op(o, put, init); -}; diff --git a/packages/graph/permissions/types.ts b/packages/graph/permissions/types.ts index 518236bf4..ca5cddb95 100644 --- a/packages/graph/permissions/types.ts +++ b/packages/graph/permissions/types.ts @@ -1,8 +1,7 @@ import { body } from "@pnp/queryable"; import { IDeleteable, IGetById, IUpdateable, defaultPath, deleteable, getById, updateable } from "../decorators.js"; -import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js"; +import { graphInvokableFactory, _GraphCollection, _GraphInstance, graphPost } from "../graphqueryable.js"; import { Permission as IPermissionType } from "@microsoft/microsoft-graph-types"; -import { graphPost } from "../ops.js"; /** * Permission diff --git a/packages/graph/photos/types.ts b/packages/graph/photos/types.ts index f9e26ca50..0fddcc423 100644 --- a/packages/graph/photos/types.ts +++ b/packages/graph/photos/types.ts @@ -1,8 +1,7 @@ -import { _GraphInstance, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphInstance, graphInvokableFactory, graphPatch } from "../graphqueryable.js"; import { BlobParse, BufferParse } from "@pnp/queryable"; import { Photo as IPhotoType } from "@microsoft/microsoft-graph-types"; import { defaultPath } from "../decorators.js"; -import { graphPatch } from "../ops.js"; @defaultPath("photo") export class _Photo extends _GraphInstance { diff --git a/packages/graph/planner/types.ts b/packages/graph/planner/types.ts index 688b92528..daf3f34c1 100644 --- a/packages/graph/planner/types.ts +++ b/packages/graph/planner/types.ts @@ -7,9 +7,8 @@ import { Planner as IPlannerType, } from "@microsoft/microsoft-graph-types"; import { body } from "@pnp/queryable"; -import { _GraphInstance, _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphInstance, _GraphCollection, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { getById, IGetById, deleteableWithETag, IDeleteableWithETag, updateableWithETag, IUpdateableWithETag } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; /** diff --git a/packages/graph/search/types.ts b/packages/graph/search/types.ts index 11755a119..7e629311e 100644 --- a/packages/graph/search/types.ts +++ b/packages/graph/search/types.ts @@ -1,8 +1,7 @@ import { SearchRequest as ISearchRequestType, SearchResponse as ISearchResponseType } from "@microsoft/microsoft-graph-types"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { GraphInit, graphInvokableFactory, _GraphInstance } from "../graphqueryable.js"; -import { graphPost } from "../ops.js"; +import { GraphInit, graphInvokableFactory, _GraphInstance, graphPost } from "../graphqueryable.js"; /** * Search diff --git a/packages/graph/sites/types.ts b/packages/graph/sites/types.ts index c649f2c00..9fc136f15 100644 --- a/packages/graph/sites/types.ts +++ b/packages/graph/sites/types.ts @@ -1,8 +1,7 @@ import { combine } from "@pnp/core"; import { defaultPath } from "../decorators.js"; -import { graphInvokableFactory, _GraphCollection, _GraphInstance } from "../graphqueryable.js"; +import { graphInvokableFactory, _GraphCollection, _GraphInstance, graphPost } from "../graphqueryable.js"; import { Site as ISiteType } from "@microsoft/microsoft-graph-types"; -import { graphPost } from "../ops.js"; import { body } from "@pnp/queryable"; /** diff --git a/packages/graph/subscriptions/types.ts b/packages/graph/subscriptions/types.ts index 067a05a05..a69abb873 100644 --- a/packages/graph/subscriptions/types.ts +++ b/packages/graph/subscriptions/types.ts @@ -1,8 +1,7 @@ -import { _GraphInstance, _GraphCollection, graphInvokableFactory } from "../graphqueryable.js"; +import { _GraphInstance, _GraphCollection, graphInvokableFactory, graphPost } from "../graphqueryable.js"; import { body } from "@pnp/queryable"; import { Subscription as ISubscriptionType } from "@microsoft/microsoft-graph-types"; import { defaultPath, deleteable, IDeleteable, IUpdateable, updateable, getById, IGetById } from "../decorators.js"; -import { graphPost } from "../ops.js"; /** * Subscription diff --git a/packages/graph/teams/index.ts b/packages/graph/teams/index.ts index 0b92df464..dbc29897a 100644 --- a/packages/graph/teams/index.ts +++ b/packages/graph/teams/index.ts @@ -3,7 +3,7 @@ import { GraphFI } from "../fi.js"; import { _Group, Group } from "../groups/types.js"; import { ITeamCreateResult, ITeam, Team, ITeams, Teams } from "./types.js"; import { Team as ITeamType } from "@microsoft/microsoft-graph-types"; -import { graphPut } from "../ops.js"; +import { graphPut } from "../graphqueryable.js"; import "./users.js"; diff --git a/packages/graph/teams/types.ts b/packages/graph/teams/types.ts index d42b2fb89..7ac7c401c 100644 --- a/packages/graph/teams/types.ts +++ b/packages/graph/teams/types.ts @@ -1,7 +1,6 @@ -import { _GraphInstance, _GraphCollection, graphInvokableFactory, GraphInstance } from "../graphqueryable.js"; +import { _GraphInstance, _GraphCollection, graphInvokableFactory, GraphInstance, graphPost } from "../graphqueryable.js"; import { body, HeaderParse } from "@pnp/queryable"; import { updateable, IUpdateable, getById, IGetById, deleteable, IDeleteable } from "../decorators.js"; -import { graphPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; import { Team as ITeamType, diff --git a/packages/sp/appcatalog/types.ts b/packages/sp/appcatalog/types.ts index ce5f34157..d40a27443 100644 --- a/packages/sp/appcatalog/types.ts +++ b/packages/sp/appcatalog/types.ts @@ -4,8 +4,8 @@ import { _SPInstance, ISPQueryable, SPCollection, + spPost, } from "../spqueryable.js"; -import { spPost } from "../ops.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { File, IFile } from "../files/types.js"; diff --git a/packages/sp/attachments/types.ts b/packages/sp/attachments/types.ts index 46b48ab9a..e53157108 100644 --- a/packages/sp/attachments/types.ts +++ b/packages/sp/attachments/types.ts @@ -1,13 +1,13 @@ import { headers } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; import { ReadableFile } from "../files/readable-file.js"; -import { spPost } from "../ops.js"; import { encodePath } from "../utils/encode-path-str.js"; import { IDeleteableWithETag, _SPCollection, spInvokableFactory, deleteableWithETag, + spPost, } from "../spqueryable.js"; @defaultPath("AttachmentFiles") diff --git a/packages/sp/batching.ts b/packages/sp/batching.ts index 172133abc..5b3d4f025 100644 --- a/packages/sp/batching.ts +++ b/packages/sp/batching.ts @@ -1,7 +1,6 @@ import { getGUID, isUrlAbsolute, combine, CopyFrom, TimelinePipe, isFunc, hOP } from "@pnp/core"; import { parseBinderWithErrorCheck, Queryable } from "@pnp/queryable"; -import { spPost } from "./ops.js"; -import { ISPQueryable, _SPQueryable } from "./spqueryable.js"; +import { ISPQueryable, _SPQueryable, spPost } from "./spqueryable.js"; import { spfi, SPFI } from "./fi.js"; import { Web, IWeb, _Web } from "./webs/types.js"; diff --git a/packages/sp/behaviors/request-digest.ts b/packages/sp/behaviors/request-digest.ts index 0f5455984..f90a70fa2 100644 --- a/packages/sp/behaviors/request-digest.ts +++ b/packages/sp/behaviors/request-digest.ts @@ -1,8 +1,7 @@ import { combine, dateAdd, hOP, isFunc, objectDefinedNotNull, TimelinePipe } from "@pnp/core"; import { JSONParse, Queryable } from "@pnp/queryable"; import { extractWebUrl } from "../utils/extract-web-url.js"; -import { ISPQueryable, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../ops.js"; +import { ISPQueryable, SPQueryable, spPost } from "../spqueryable.js"; import { BatchNever } from "../batching.js"; interface IDigestInfo { diff --git a/packages/sp/clientside-pages/types.ts b/packages/sp/clientside-pages/types.ts index 71880a408..e90613520 100644 --- a/packages/sp/clientside-pages/types.ts +++ b/packages/sp/clientside-pages/types.ts @@ -2,13 +2,12 @@ import { body, headers } from "@pnp/queryable"; import { getGUID, hOP, stringIsNullOrEmpty, objectDefinedNotNull, combine, isUrlAbsolute, isArray } from "@pnp/core"; import { IFile, IFileInfo } from "../files/types.js"; import { Item, IItem } from "../items/types.js"; -import { _SPQueryable, SPQueryable, SPCollection, SPInit } from "../spqueryable.js"; +import { _SPQueryable, SPQueryable, SPCollection, SPInit, spPost } from "../spqueryable.js"; import { List } from "../lists/types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { Web, IWeb } from "../webs/types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { Site } from "../sites/types.js"; -import { spPost } from "../ops.js"; import { getNextOrder, reindex } from "./funcs.js"; import "../files/web.js"; import "../comments/item.js"; diff --git a/packages/sp/clientside-pages/web.ts b/packages/sp/clientside-pages/web.ts index 8487e65e9..b0b4bd325 100644 --- a/packages/sp/clientside-pages/web.ts +++ b/packages/sp/clientside-pages/web.ts @@ -9,8 +9,7 @@ import { IRepostPage, ClientsideWebpart, } from "./types.js"; -import { SPCollection, SPInstance } from "../spqueryable.js"; -import { spPost } from "../ops.js"; +import { SPCollection, SPInstance, spPost } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { extractWebUrl } from "@pnp/sp"; diff --git a/packages/sp/column-defaults/list.ts b/packages/sp/column-defaults/list.ts index 6c60d6bbc..44a3ec998 100644 --- a/packages/sp/column-defaults/list.ts +++ b/packages/sp/column-defaults/list.ts @@ -4,7 +4,7 @@ import { Folder } from "../folders/types.js"; import { IFieldDefault } from "./types.js"; import { IResourcePath } from "../utils/to-resource-path.js"; import { combine, isArray } from "@pnp/core"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; import { SPCollection } from "../presets/all.js"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/comments/clientside-page.ts b/packages/sp/comments/clientside-page.ts index 0d836eefc..b2db9d5e7 100644 --- a/packages/sp/comments/clientside-page.ts +++ b/packages/sp/comments/clientside-page.ts @@ -1,8 +1,7 @@ import { _ClientsidePage } from "../clientside-pages/types.js"; import { ICommentInfo, IComment, ILikedByInformation } from "./types.js"; import { IItemUpdateResult, Item } from "../items/index.js"; -import { spPost } from "../ops.js"; -import { SPQueryable } from "../spqueryable.js"; +import { SPQueryable, spPost } from "../spqueryable.js"; declare module "../clientside-pages/types" { interface _ClientsidePage { diff --git a/packages/sp/comments/item.ts b/packages/sp/comments/item.ts index b15f0bf2b..f81109471 100644 --- a/packages/sp/comments/item.ts +++ b/packages/sp/comments/item.ts @@ -1,10 +1,9 @@ import { addProp } from "@pnp/queryable"; import { _Item, Item } from "../items/types.js"; import { Comments, IComments, ILikeData, ILikedByInformation, RatingValues } from "./types.js"; -import { spPost } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine } from "@pnp/core"; -import { SPQueryable } from "../spqueryable.js"; +import { SPQueryable, spPost } from "../spqueryable.js"; declare module "../items/types" { interface _Item { diff --git a/packages/sp/comments/types.ts b/packages/sp/comments/types.ts index 2f518ffc6..e9c859ea6 100644 --- a/packages/sp/comments/types.ts +++ b/packages/sp/comments/types.ts @@ -3,10 +3,11 @@ import { _SPCollection, spInvokableFactory, _SPInstance, + spDelete, + spPost, } from "../spqueryable.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { body } from "@pnp/queryable"; -import { spDelete, spPost } from "../ops.js"; @defaultPath("comments") export class _Comments extends _SPCollection { diff --git a/packages/sp/content-types/types.ts b/packages/sp/content-types/types.ts index 79f7c1e0b..6b029e6e1 100644 --- a/packages/sp/content-types/types.ts +++ b/packages/sp/content-types/types.ts @@ -7,9 +7,10 @@ import { ISPCollection, deleteable, IDeleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; @defaultPath("contenttypes") export class _ContentTypes extends _SPCollection { diff --git a/packages/sp/context-info/index.ts b/packages/sp/context-info/index.ts index 5c3383381..ac06cfd01 100644 --- a/packages/sp/context-info/index.ts +++ b/packages/sp/context-info/index.ts @@ -1,6 +1,5 @@ import { hOP } from "@pnp/core"; -import { spPost } from "../ops.js"; -import { SPQueryable, _SPQueryable } from "../spqueryable.js"; +import { SPQueryable, _SPQueryable, spPost } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; declare module "../spqueryable" { diff --git a/packages/sp/favorites/types.ts b/packages/sp/favorites/types.ts index c223f8e51..b8e21106e 100644 --- a/packages/sp/favorites/types.ts +++ b/packages/sp/favorites/types.ts @@ -1,7 +1,6 @@ import { defaultPath } from "../decorators.js"; -import { _SPInstance, spInvokableFactory, _SPCollection, SPInit } from "../spqueryable.js"; +import { _SPInstance, spInvokableFactory, _SPCollection, SPInit, spPost } from "../spqueryable.js"; import { hOP } from "@pnp/core"; -import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; import { SharepointIds, ResourceVisualization } from "@microsoft/microsoft-graph-types"; diff --git a/packages/sp/features/types.ts b/packages/sp/features/types.ts index 9b7cdc64f..661249f5c 100644 --- a/packages/sp/features/types.ts +++ b/packages/sp/features/types.ts @@ -3,9 +3,9 @@ import { _SPInstance, _SPCollection, spInvokableFactory, + spPost, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; @defaultPath("features") export class _Features extends _SPCollection { diff --git a/packages/sp/fields/types.ts b/packages/sp/fields/types.ts index 20476566e..2479af899 100644 --- a/packages/sp/fields/types.ts +++ b/packages/sp/fields/types.ts @@ -5,9 +5,10 @@ import { deleteable, spInvokableFactory, IDeleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { metadata } from "../utils/metadata.js"; @defaultPath("fields") diff --git a/packages/sp/files/types.ts b/packages/sp/files/types.ts index e94473039..13b978315 100644 --- a/packages/sp/files/types.ts +++ b/packages/sp/files/types.ts @@ -10,11 +10,12 @@ import { ISPQueryable, deleteable, IDeleteable, + spPost, + spGet, } from "../spqueryable.js"; import { Item, IItem } from "../items/index.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spGet } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { toResourcePath } from "../utils/to-resource-path.js"; import { ISiteUserProps } from "../site-users/types.js"; diff --git a/packages/sp/folders/types.ts b/packages/sp/folders/types.ts index e54b43964..abb637cb1 100644 --- a/packages/sp/folders/types.ts +++ b/packages/sp/folders/types.ts @@ -9,11 +9,12 @@ import { ISPInstance, IDeleteableWithETag, ISPQueryable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { IItem, Item } from "../items/types.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { toResourcePath, IResourcePath } from "../utils/to-resource-path.js"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/groupsitemanager/types.ts b/packages/sp/groupsitemanager/types.ts index f3a2a35f9..e6f205aed 100644 --- a/packages/sp/groupsitemanager/types.ts +++ b/packages/sp/groupsitemanager/types.ts @@ -1,5 +1,6 @@ import { body, BufferParse } from "@pnp/queryable"; -import { _SPInstance, defaultPath, spPost, spInvokableFactory, ISPQueryable, spGet } from "@pnp/sp"; +import { _SPInstance, spPost, spInvokableFactory, ISPQueryable, spGet } from "../spqueryable.js"; +import { defaultPath } from "../decorators.js"; @defaultPath("_api/groupsitemanager") class _GroupSiteManager extends _SPInstance> { diff --git a/packages/sp/hubsites/site.ts b/packages/sp/hubsites/site.ts index 4adb0c379..5be378797 100644 --- a/packages/sp/hubsites/site.ts +++ b/packages/sp/hubsites/site.ts @@ -1,5 +1,5 @@ import { _Site, Site } from "../sites/types.js"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; declare module "../sites/types" { interface _Site { diff --git a/packages/sp/hubsites/web.ts b/packages/sp/hubsites/web.ts index 34bc7450e..7d409aebc 100644 --- a/packages/sp/hubsites/web.ts +++ b/packages/sp/hubsites/web.ts @@ -1,6 +1,6 @@ import { _Web, Web } from "../webs/types.js"; import { IHubSiteWebData } from "./types.js"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; declare module "../webs/types" { interface _Web { diff --git a/packages/sp/index.ts b/packages/sp/index.ts index 7a5e76e32..188a5bd3d 100644 --- a/packages/sp/index.ts +++ b/packages/sp/index.ts @@ -2,8 +2,6 @@ export * from "./spqueryable.js"; export * from "./decorators.js"; -export * from "./ops.js"; - export { SPFI, spfi, diff --git a/packages/sp/items/types.ts b/packages/sp/items/types.ts index b39ee2552..a1c33fa35 100644 --- a/packages/sp/items/types.ts +++ b/packages/sp/items/types.ts @@ -9,6 +9,7 @@ import { SPInstance, ISPInstance, SPCollection, + spPost, } from "../spqueryable.js"; import { hOP, objectDefinedNotNull } from "@pnp/core"; import { extractWebUrl } from "@pnp/sp"; @@ -16,7 +17,6 @@ import { IListItemFormUpdateValue, List } from "../lists/types.js"; import { body, headers, parseBinderWithErrorCheck, parseODataJSON } from "@pnp/queryable"; import { IList } from "../lists/index.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; import { IResourcePath } from "../utils/to-resource-path.js"; /** diff --git a/packages/sp/lists/types.ts b/packages/sp/lists/types.ts index 22f55fc06..17625d6aa 100644 --- a/packages/sp/lists/types.ts +++ b/packages/sp/lists/types.ts @@ -10,11 +10,12 @@ import { ISPCollection, SPCollection, IDeleteableWithETag, + spPost, + spPostMerge, } from "../spqueryable.js"; import { IChangeQuery } from "../types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { IBasePermissions } from "../security/types.js"; import { IFieldInfo } from "../fields/types.js"; import { IFormInfo } from "../forms/types.js"; diff --git a/packages/sp/navigation/types.ts b/packages/sp/navigation/types.ts index 62c4e8167..d6355eb5d 100644 --- a/packages/sp/navigation/types.ts +++ b/packages/sp/navigation/types.ts @@ -6,10 +6,11 @@ import { _SPQueryable, IDeleteable, ISPQueryable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../index.js"; import { combine } from "@pnp/core"; diff --git a/packages/sp/ops.ts b/packages/sp/ops.ts deleted file mode 100644 index a83491bb8..000000000 --- a/packages/sp/ops.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { op, get, post, patch, del } from "@pnp/queryable"; -import { ISPQueryable } from "./spqueryable.js"; - -export const spGet = (o: ISPQueryable, init?: RequestInit): Promise => { - return op(o, get, init); -}; - -export const spPost = (o: ISPQueryable, init?: RequestInit): Promise => op(o, post, init); - -export const spPostMerge = (o: ISPQueryable, init?: RequestInit): Promise => { - init = init || {}; - init.headers = { ...init.headers, "X-HTTP-Method": "MERGE" }; - - return spPost(o, init); -}; - -export const spPostDelete = (o: ISPQueryable, init?: RequestInit): Promise => { - init = init || {}; - init.headers = { ...init.headers || {}, "X-HTTP-Method": "DELETE" }; - - return spPost(o, init); -}; - -export const spPostDeleteETag = (o: ISPQueryable, init?: RequestInit, eTag = "*"): Promise => { - init = init || {}; - init.headers = { ...init.headers || {}, "IF-Match": eTag }; - - return spPostDelete(o, init); -}; - -export const spDelete = (o: ISPQueryable, init?: RequestInit): Promise => op(o, del, init); - -export const spPatch = (o: ISPQueryable, init?: RequestInit): Promise => op(o, patch, init); diff --git a/packages/sp/profiles/types.ts b/packages/sp/profiles/types.ts index 7be913395..4bc5461fb 100644 --- a/packages/sp/profiles/types.ts +++ b/packages/sp/profiles/types.ts @@ -6,11 +6,11 @@ import { ISPInstance, spInvokableFactory, _SPQueryable, + spPost, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { PrincipalType, PrincipalSource } from "../types.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; import { AssignFrom } from "@pnp/core"; export class _Profiles extends _SPInstance { diff --git a/packages/sp/recycle-bin/types.ts b/packages/sp/recycle-bin/types.ts index 29dd2e31d..4b0fdb1bf 100644 --- a/packages/sp/recycle-bin/types.ts +++ b/packages/sp/recycle-bin/types.ts @@ -3,9 +3,9 @@ import { spInvokableFactory, SPQueryable, _SPInstance, + spPost, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; /** * Describes a recycle bin item diff --git a/packages/sp/regional-settings/funcs.ts b/packages/sp/regional-settings/funcs.ts index 21fd2799b..09878c65f 100644 --- a/packages/sp/regional-settings/funcs.ts +++ b/packages/sp/regional-settings/funcs.ts @@ -1,5 +1,4 @@ -import { _SPQueryable, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../ops.js"; +import { _SPQueryable, SPQueryable, spPost } from "../spqueryable.js"; import { body } from "@pnp/queryable"; export function getValueForUICultureBinder(propName: string): (this: _SPQueryable, cultureName: string) => Promise { diff --git a/packages/sp/regional-settings/types.ts b/packages/sp/regional-settings/types.ts index f976e8dbc..eb28e478a 100644 --- a/packages/sp/regional-settings/types.ts +++ b/packages/sp/regional-settings/types.ts @@ -4,9 +4,9 @@ import { SPCollection, spInvokableFactory, _SPCollection, + spPost, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; @defaultPath("regionalsettings") export class _RegionalSettings extends _SPInstance { diff --git a/packages/sp/related-items/types.ts b/packages/sp/related-items/types.ts index d89c02a9b..4fe3e0b72 100644 --- a/packages/sp/related-items/types.ts +++ b/packages/sp/related-items/types.ts @@ -1,7 +1,6 @@ -import { _SPQueryable, ISPQueryable } from "../spqueryable.js"; +import { _SPQueryable, ISPQueryable, spPost } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { defaultPath } from "../decorators.js"; -import { spPost } from "../ops.js"; import { body } from "@pnp/queryable"; @defaultPath("_api/SP.RelatedItemManager") diff --git a/packages/sp/search/query.ts b/packages/sp/search/query.ts index 760b1d931..e1b12c564 100644 --- a/packages/sp/search/query.ts +++ b/packages/sp/search/query.ts @@ -1,8 +1,7 @@ -import { _SPInstance, spInvokableFactory, SPInit } from "../spqueryable.js"; +import { _SPInstance, spInvokableFactory, SPInit, spPost } from "../spqueryable.js"; import { getHashCode, hOP, isArray } from "@pnp/core"; import { body, CacheAlways, CacheKey, invokable } from "@pnp/queryable"; import { ISearchQuery, ISearchResponse, ISearchResult, ISearchBuilder, SearchQueryInit } from "./types.js"; -import { spPost } from "../ops.js"; import { defaultPath } from "../decorators.js"; const funcs = new Map([ diff --git a/packages/sp/security/funcs.ts b/packages/sp/security/funcs.ts index 7268df72d..48b6b9cbd 100644 --- a/packages/sp/security/funcs.ts +++ b/packages/sp/security/funcs.ts @@ -1,6 +1,5 @@ import { SecurableQueryable, IBasePermissions, PermissionKind } from "./types.js"; -import { SPInstance, SPQueryable } from "../spqueryable.js"; -import { spPost } from "../ops.js"; +import { SPInstance, SPQueryable, spPost } from "../spqueryable.js"; /** * Gets the effective permissions for the user supplied diff --git a/packages/sp/security/types.ts b/packages/sp/security/types.ts index 5e0b62a49..5e084303d 100644 --- a/packages/sp/security/types.ts +++ b/packages/sp/security/types.ts @@ -8,10 +8,11 @@ import { SPCollection, ISPCollection, IDeleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { SiteGroups, ISiteGroups } from "../site-groups/types.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; export type SecurableQueryable = _SPInstance & ISecurableMethods; diff --git a/packages/sp/sharing/funcs.ts b/packages/sp/sharing/funcs.ts index 52ad032a5..9849c2809 100644 --- a/packages/sp/sharing/funcs.ts +++ b/packages/sp/sharing/funcs.ts @@ -1,6 +1,6 @@ import { body } from "@pnp/queryable"; import { isArray, jsS } from "@pnp/core"; -import { SPCollection, SPInstance } from "../spqueryable.js"; +import { SPCollection, SPInstance, spPost } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { Web } from "../webs/types.js"; import { @@ -18,7 +18,6 @@ import { ISharingEmailData, RoleType, } from "./types.js"; -import { spPost } from "../ops.js"; import { RoleDefinitions } from "../security/types.js"; import { emptyGuid } from "../types.js"; diff --git a/packages/sp/sharing/web.ts b/packages/sp/sharing/web.ts index 3d691d4a4..9ce75f2a6 100644 --- a/packages/sp/sharing/web.ts +++ b/packages/sp/sharing/web.ts @@ -4,7 +4,7 @@ import { RoleType } from "./types.js"; import { shareObject } from "./funcs.js"; import { combine } from "@pnp/core"; import { body } from "@pnp/queryable"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; /** * Extend _Web diff --git a/packages/sp/site-designs/types.ts b/packages/sp/site-designs/types.ts index 609957a9e..5b90d120a 100644 --- a/packages/sp/site-designs/types.ts +++ b/packages/sp/site-designs/types.ts @@ -1,10 +1,8 @@ -import { ISPQueryable, _SPQueryable } from "../spqueryable.js"; +import { ISPQueryable, _SPQueryable, spPost } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { headers, body } from "@pnp/queryable"; -import { spPost } from "../ops.js"; import { combine, hOP } from "@pnp/core"; - export class _SiteDesigns extends _SPQueryable { constructor(base: string | ISPQueryable, methodName = "") { diff --git a/packages/sp/site-groups/types.ts b/packages/sp/site-groups/types.ts index 63000403f..a3ed9f964 100644 --- a/packages/sp/site-groups/types.ts +++ b/packages/sp/site-groups/types.ts @@ -2,11 +2,12 @@ import { _SPCollection, spInvokableFactory, _SPInstance, + spPost, + spPostMerge, } from "../spqueryable.js"; import { SiteUsers, ISiteUsers } from "../site-users/types.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; @defaultPath("sitegroups") export class _SiteGroups extends _SPCollection { diff --git a/packages/sp/site-groups/web.ts b/packages/sp/site-groups/web.ts index 5b6f8ad04..b49d17cba 100644 --- a/packages/sp/site-groups/web.ts +++ b/packages/sp/site-groups/web.ts @@ -1,5 +1,5 @@ import { addProp } from "@pnp/queryable"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; import { Web, _Web } from "../webs/types.js"; import { ISiteGroups, SiteGroups, ISiteGroup, SiteGroup } from "./types.js"; import "../security/web.js"; diff --git a/packages/sp/site-scripts/types.ts b/packages/sp/site-scripts/types.ts index a652e178d..0cc38aff9 100644 --- a/packages/sp/site-scripts/types.ts +++ b/packages/sp/site-scripts/types.ts @@ -1,6 +1,5 @@ import { body } from "@pnp/queryable"; -import { spPost } from "../ops.js"; -import { ISPQueryable, _SPQueryable } from "../spqueryable.js"; +import { ISPQueryable, _SPQueryable, spPost } from "../spqueryable.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine } from "@pnp/core"; import { encodePath } from "../utils/encode-path-str.js"; diff --git a/packages/sp/site-users/types.ts b/packages/sp/site-users/types.ts index ce173197b..a30e3f451 100644 --- a/packages/sp/site-users/types.ts +++ b/packages/sp/site-users/types.ts @@ -4,11 +4,12 @@ import { _SPInstance, IDeleteable, deleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { SiteGroups, ISiteGroups } from "../site-groups/types.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { PrincipalType } from "../types.js"; @defaultPath("siteusers") diff --git a/packages/sp/site-users/web.ts b/packages/sp/site-users/web.ts index 8bb0cd0e9..97be709ca 100644 --- a/packages/sp/site-users/web.ts +++ b/packages/sp/site-users/web.ts @@ -2,7 +2,7 @@ import { addProp, body } from "@pnp/queryable"; import { _Web, Web } from "../webs/types.js"; import { ISiteUsers, SiteUsers, ISiteUser, SiteUser, IWebEnsureUserResult } from "./types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPost } from "../ops.js"; +import { spPost } from "../spqueryable.js"; declare module "../webs/types" { interface _Web { diff --git a/packages/sp/sites/types.ts b/packages/sp/sites/types.ts index a7c7997c4..a1de6f33f 100644 --- a/packages/sp/sites/types.ts +++ b/packages/sp/sites/types.ts @@ -1,10 +1,9 @@ -import { _SPInstance, spInvokableFactory, SPInit, SPQueryable } from "../spqueryable.js"; +import { _SPInstance, spInvokableFactory, SPInit, SPQueryable, spPatch, spPost } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { Web, IWeb } from "../webs/types.js"; import { combine, hOP, isArray } from "@pnp/core"; import { body, TextParse } from "@pnp/queryable"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPatch, spPost } from "../ops.js"; import { IChangeQuery } from "../types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { emptyGuid } from "../types.js"; diff --git a/packages/sp/social/types.ts b/packages/sp/social/types.ts index dcac9231c..dd1e1501b 100644 --- a/packages/sp/social/types.ts +++ b/packages/sp/social/types.ts @@ -2,11 +2,11 @@ import { _SPInstance, ISPQueryable, SPInit, + spPost, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { hOP } from "@pnp/core"; import { body } from "@pnp/queryable"; -import { spPost } from "../ops.js"; @defaultPath("_api/social.following") export class _Social extends _SPInstance implements ISocial { diff --git a/packages/sp/spqueryable.ts b/packages/sp/spqueryable.ts index c377f83ed..775e2db6b 100644 --- a/packages/sp/spqueryable.ts +++ b/packages/sp/spqueryable.ts @@ -1,6 +1,5 @@ import { combine, isUrlAbsolute, isArray, objectDefinedNotNull, stringIsNullOrEmpty } from "@pnp/core"; -import { IInvokable, Queryable, queryableFactory } from "@pnp/queryable"; -import { spPostDelete, spPostDeleteETag } from "./ops.js"; +import { IInvokable, Queryable, queryableFactory, op, get, post, patch, del } from "@pnp/queryable"; export type SPInit = string | ISPQueryable | [ISPQueryable, string]; @@ -242,3 +241,34 @@ export interface IDeleteableWithETag { */ delete(eTag?: string): Promise; } + +export const spGet = (o: ISPQueryable, init?: RequestInit): Promise => { + return op(o, get, init); +}; + +export const spPost = (o: ISPQueryable, init?: RequestInit): Promise => op(o, post, init); + +export const spPostMerge = (o: ISPQueryable, init?: RequestInit): Promise => { + init = init || {}; + init.headers = { ...init.headers, "X-HTTP-Method": "MERGE" }; + + return spPost(o, init); +}; + +export const spPostDelete = (o: ISPQueryable, init?: RequestInit): Promise => { + init = init || {}; + init.headers = { ...init.headers || {}, "X-HTTP-Method": "DELETE" }; + + return spPost(o, init); +}; + +export const spPostDeleteETag = (o: ISPQueryable, init?: RequestInit, eTag = "*"): Promise => { + init = init || {}; + init.headers = { ...init.headers || {}, "IF-Match": eTag }; + + return spPostDelete(o, init); +}; + +export const spDelete = (o: ISPQueryable, init?: RequestInit): Promise => op(o, del, init); + +export const spPatch = (o: ISPQueryable, init?: RequestInit): Promise => op(o, patch, init); diff --git a/packages/sp/sputilities/types.ts b/packages/sp/sputilities/types.ts index db1e8c653..ce49ca528 100644 --- a/packages/sp/sputilities/types.ts +++ b/packages/sp/sputilities/types.ts @@ -1,8 +1,7 @@ import { body } from "@pnp/queryable"; -import { _SPQueryable, spInvokableFactory, ISPQueryable, SPInit } from "../spqueryable.js"; +import { _SPQueryable, spInvokableFactory, ISPQueryable, SPInit, spPost } from "../spqueryable.js"; import { IPrincipalInfo, PrincipalType, PrincipalSource } from "../types.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; -import { spPost } from "../ops.js"; import { combine } from "@pnp/core"; export class _Utilities extends _SPQueryable implements IUtilities { diff --git a/packages/sp/subscriptions/types.ts b/packages/sp/subscriptions/types.ts index 4406c30ed..066265368 100644 --- a/packages/sp/subscriptions/types.ts +++ b/packages/sp/subscriptions/types.ts @@ -2,10 +2,12 @@ import { _SPCollection, spInvokableFactory, _SPInstance, + spPost, + spPatch, + spDelete, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPatch, spDelete } from "../ops.js"; @defaultPath("subscriptions") export class _Subscriptions extends _SPCollection { diff --git a/packages/sp/taxonomy/types.ts b/packages/sp/taxonomy/types.ts index ccf2b5024..5f3957d02 100644 --- a/packages/sp/taxonomy/types.ts +++ b/packages/sp/taxonomy/types.ts @@ -1,8 +1,7 @@ import { isArray } from "@pnp/core"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spDelete, spPatch, spPost } from "../ops.js"; -import { _SPInstance, spInvokableFactory, _SPCollection } from "../spqueryable.js"; +import { _SPInstance, spInvokableFactory, _SPCollection, spDelete, spPatch, spPost } from "../spqueryable.js"; import { encodePath } from "../utils/encode-path-str.js"; /** diff --git a/packages/sp/user-custom-actions/types.ts b/packages/sp/user-custom-actions/types.ts index be1f28be7..d3d98136d 100644 --- a/packages/sp/user-custom-actions/types.ts +++ b/packages/sp/user-custom-actions/types.ts @@ -4,10 +4,11 @@ import { deleteable, _SPInstance, IDeleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { IBasePermissions } from "../security/index.js"; @defaultPath("usercustomactions") diff --git a/packages/sp/views/types.ts b/packages/sp/views/types.ts index 2ec295a36..e240cdfbd 100644 --- a/packages/sp/views/types.ts +++ b/packages/sp/views/types.ts @@ -5,9 +5,10 @@ import { _SPInstance, deleteable, IDeleteable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; -import { spPost, spPostMerge } from "../ops.js"; import { encodePath } from "../utils/encode-path-str.js"; @defaultPath("views") diff --git a/packages/sp/webparts/types.ts b/packages/sp/webparts/types.ts index ac80a2939..87edec000 100644 --- a/packages/sp/webparts/types.ts +++ b/packages/sp/webparts/types.ts @@ -7,9 +7,9 @@ import { spInvokableFactory, SPInstance, ISPInstance, + spPost, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; -import { spPost } from "../ops.js"; export class _LimitedWebPartManager extends _SPQueryable implements ILimitedWebPartManager { diff --git a/packages/sp/webs/types.ts b/packages/sp/webs/types.ts index 077cb9f6b..afce2af61 100644 --- a/packages/sp/webs/types.ts +++ b/packages/sp/webs/types.ts @@ -11,11 +11,12 @@ import { deleteable, SPInit, ISPQueryable, + spPost, + spPostMerge, } from "../spqueryable.js"; import { defaultPath } from "../decorators.js"; import { IChangeQuery } from "../types.js"; import { odataUrlFrom } from "../utils/odata-url-from.js"; -import { spPost, spPostMerge } from "../ops.js"; import { extractWebUrl } from "../utils/extract-web-url.js"; import { combine, isArray } from "@pnp/core"; import { encodePath } from "../utils/encode-path-str.js";