diff --git a/docs/graph/taxonomy.md b/docs/graph/taxonomy.md new file mode 100644 index 000000000..79055a5c3 --- /dev/null +++ b/docs/graph/taxonomy.md @@ -0,0 +1,442 @@ +# @pnp/graph/taxonomy + +Provides access to the v1.0 api term store + +[![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) + +![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) + +## Term Store + +Access tenant termstore + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermStore } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term store data +const info: ITermStore = await graph.termStore(); +``` + +Access site specific termstore + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term store data +const info: ITermStoreInfo = await graph.sites.getById("contoso.sharepoint.com,91dd2418-8fb9-4e0e-919d-c1b31e938386,285cc5a1-cf50-4e4d-8d93-5ba5a8e76e01").termStore(); + +``` +### SearchTerm + +Search for terms starting with provided label under entire termStore or a termSet or a parent term. + +The following properties are valid for the supplied query: `label: string`, `setId?: string`, `parentTermId?: string`, `languageTag?: string`, `stringMatchOption?: "ExactMatch" | "StartsWith"`. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// minimally requires the label +const results1 = await graph.termStore.searchTerm({ + label: "test", +}); + +// other properties can be included as needed +const results2 = await graph.termStore.searchTerm({ + label: "test", + setId: "{guid}", +}); + +// other properties can be included as needed +const results3 = await graph.termStore.searchTerm({ + label: "test", + setId: "{guid}", + stringMatchOption: "ExactMatch", +}); +``` + +### Update + +Allows you to update language setttings for the store + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +await graph.termStore.update({ + defaultLanguageTag: "en-US", + languageTags: ["en-US", "en-IE", "de-DE"], +}); +``` + +## Term Groups + +Access term group information + +### List + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term groups +const info: ITermGroupInfo[] = await graph.termStore.groups(); +``` + +### Get By Id + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term groups data +const info: ITermGroupInfo = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72")(); +``` + +### Add + +Allows you to add a term group to a store. + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); +const groupInfo: ITermGroupInfo = await graph.termStore.groups.add({ + displayName: "Accounting", + description: "Term Group for Accounting", + name: "accounting1", + scope: "global", +}); +``` + +## Term Group + +### Delete + +Allows you to add a term group to a store. + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").delete(); +``` + +## Term Sets + +Access term set information + +### List + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermSetInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get set info +const info: ITermSetInfo[] = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets(); +``` + +### Get By Id + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermSetInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term set data by group id then by term set id +const info: ITermSetInfo = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72")(); + +// get term set data by term set id +const infoByTermSetId: ITermSetInfo = await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72")(); +``` + +### Add + +Allows you to add a term set. + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// when adding a set directly from the root .sets property, you must include the "parentGroup" property +const setInfo = await graph.termStore.sets.add({ + parentGroup: { + id: "338666a8-1111-2222-3333-f72471314e72" + }, + contact: "steve", + description: "description", + isAvailableForTagging: true, + isOpen: true, + localizedNames: [{ + name: "MySet", + languageTag: "en-US", + }], + properties: [{ + key: "key1", + value: "value1", + }] +}); + +// when adding a termset through a group's sets property you do not specify the "parentGroup" property +const setInfo2 = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.add({ + contact: "steve", + description: "description", + isAvailableForTagging: true, + isOpen: true, + localizedNames: [{ + name: "MySet2", + languageTag: "en-US", + }], + properties: [{ + key: "key1", + value: "value1", + }] +}); +``` + +### getAllChildrenAsOrderedTree + +This method will get all of a set's child terms in an ordered array. It is a costly method in terms of requests so we suggest you cache the results as taxonomy trees seldom change. + +> Starting with version 2.6.0 you can now include an optional param to retrieve all of the term's properties and localProperties in the tree. Default is false. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermInfo } from "@pnp/graph/taxonomy"; +import { dateAdd, PnPClientStorage } from "@pnp/core"; + +const graph = graphfi(...); + +// here we get all the children of a given set +const childTree = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getAllChildrenAsOrderedTree(); + +// here we show caching the results using the PnPClientStorage class, there are many caching libraries and options available +const store = new PnPClientStorage(); + +// our tree likely doesn't change much in 30 minutes for most applications +// adjust to be longer or shorter as needed +const cachedTree = await store.local.getOrPut("myKey", () => { + return graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getAllChildrenAsOrderedTree(); +}, dateAdd(new Date(), "minute", 30)); + +// you can also get all the properties and localProperties +const set = graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72"); +const childTree = await set.getAllChildrenAsOrderedTree({ retrieveProperties: true }); +``` + +## TermSet + +Access term set information + +### Update + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +const termSetInfo = await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").update({ + properties: [{ + key: "MyKey2", + value: "MyValue2", + }], +}); + +const termSetInfo2 = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").update({ + properties: [{ + key: "MyKey3", + value: "MyValue3", + }], +}); +``` + +### Delete + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermGroupInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").delete(); + +await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").delete(); +``` + +## Terms + +Access term set information + +### List + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// list all the terms that are direct children of this set +const infos: ITermInfo[] = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children(); +``` + +### List (terms) + +You can use the terms property to get a flat list of all terms in the set. These terms do not contain parent/child relationship information. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// list all the terms available in this term set by group id then by term set id +const infos: ITermInfo[] = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").terms(); + +// list all the terms available in this term set by term set id +const infosByTermSetId: ITermInfo[] = await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").terms(); +``` + +### Get By Id + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get term set data +const info: ITermInfo = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72")(); +``` + +### Add + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; +import { ITermInfo } from "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +const newTermInfo = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children.add({ + labels: [ + { + isDefault: true, + languageTag: "en-us", + name: "New Term", + } + ] +}); + +const newTermInfo = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children.add({ + labels: [ + { + isDefault: true, + languageTag: "en-us", + name: "New Term 2", + } + ] +}); +``` + +## Term + +### Update + +> Note that when updating a Term if you update the `properties` it replaces the collection, so a merge of existing + new needs to be handled by your application. + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +const termInfo = await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").update({ + properties: [{ + key: "something", + value: "a value 2", + }], +}); + +const termInfo2 = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").update({ + properties: [{ + key: "something", + value: "a value", + }], +}); +``` + +### Delete + +_Added in 3.10.0_ + +```TypeScript +import { graphfi, SPFxToken, SPFx } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +const termInfo = await graph.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").delete(); + +const termInfo2 = await graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").delete(); +``` + +## Get Term Parent + +The server API changed again, resulting in the removal of the "parent" property from ITerm as it is not longer supported as a path property. You now must use "expand" to load a term's parent information. The side affect of this is that the parent is no longer chainable, meaning you need to load a new term instance to work with the parent term. An approach for this is shown below. + +```TypeScript +import { graphfi } from "@pnp/graph"; +import "@pnp/graph/taxonomy"; + +const graph = graphfi(...); + +// get a ref to the set +const set = graph.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72"); + +// get a term's information and expand parent to get the parent info as well +const w = await set.getTermById("338666a8-1111-2222-3333-f72471314e72").expand("parent")(); + +// get a ref to the parent term +const parent = set.getTermById(w.parent.id); + +// make a request for the parent term's info - this data currently match the results in the expand call above, but this +// is to demonstrate how to gain a ref to the parent and select its data +const parentInfo = await parent.select("Id", "Descriptions")(); +``` diff --git a/docs/sp/column-defaults.md b/docs/sp/column-defaults.md index 9a3d61180..ee99ac2ad 100644 --- a/docs/sp/column-defaults.md +++ b/docs/sp/column-defaults.md @@ -216,23 +216,16 @@ import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import "@pnp/sp/column-defaults"; -import "@pnp/sp/taxonomy"; const sp = spfi(...); -// get the term's info we want to use as the default -const term = await sp.termStore.sets.getById("ea6fc521-d293-4f3d-9e84-f3a5bc0936ce").getTermById("775c9cf6-c3cd-4db9-8cfa-fc0aeefad93a")(); - -// get the default term label -const defLabel = term.labels.find(v => v.isDefault); - // set the default value using -1, the term id, and the term's default label name await sp.web.lists.getByTitle("MetaDataDocLib").rootFolder.setDefaultColumnValues([{ name: "MetaDataColumnInternalName", value: { wssId: "-1", - termId: term.id, - termName: defLabel.name, + termId: "{term Id}", + termName: "{term Label}", } }]) diff --git a/docs/sp/taxonomy.md b/docs/sp/taxonomy.md deleted file mode 100644 index 224b489b3..000000000 --- a/docs/sp/taxonomy.md +++ /dev/null @@ -1,470 +0,0 @@ -# @pnp/sp/taxonomy - -Provides access to the v2.1 api term store - -### Docs updated with v2.0.9 release as the underlying API changed - -> NOTE: This API may change so please be aware updates to the taxonomy module will not trigger a major version bump in PnPjs even if they are breaking. Once things stabilize this note will be removed. - -[![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) - -![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) - -## Term Store - -Access term store data from the root sp object as shown below. - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermStoreInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get term store data -const info: ITermStoreInfo = await sp.termStore(); -``` - -### searchTerm - -_Added in 3.3.0_ - -Search for terms starting with provided label under entire termStore or a termSet or a parent term. - -The following properties are valid for the supplied query: `label: string`, `setId?: string`, `parentTermId?: string`, `languageTag?: string`, `stringMatchOption?: "ExactMatch" | "StartsWith"`. - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// minimally requires the label -const results1 = await sp.termStore.searchTerm({ - label: "test", -}); - -// other properties can be included as needed -const results2 = await sp.termStore.searchTerm({ - label: "test", - setId: "{guid}", -}); - -// other properties can be included as needed -const results3 = await sp.termStore.searchTerm({ - label: "test", - setId: "{guid}", - stringMatchOption: "ExactMatch", -}); -``` - -### update - -_Added in 3.10.0_ - -Allows you to update language setttings for the store - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -await sp.termStore.update({ - defaultLanguageTag: "en-US", - languageTags: ["en-US", "en-IE", "de-DE"], -}); -``` - -## Term Groups - -Access term group information - -### List - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get term groups -const info: ITermGroupInfo[] = await sp.termStore.groups(); -``` - -### Get By Id - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get term groups data -const info: ITermGroupInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72")(); -``` - -### Add - -_Added in 3.10.0_ - -Allows you to add a term group to a store. - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); -const groupInfo: ITermGroupInfo = await sp.termStore.groups.add({ - displayName: "Accounting", - description: "Term Group for Accounting", - name: "accounting1", - scope: "global", -}); -``` - -## Term Group - -### Delete - -_Added in 3.10.0_ - -Allows you to add a term group to a store. - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").delete(); -``` - -## Term Sets - -Access term set information - -### List - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermSetInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get set info -const info: ITermSetInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets(); -``` - -### Get By Id - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermSetInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get term set data by group id then by term set id -const info: ITermSetInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72")(); - -// get term set data by term set id -const infoByTermSetId: ITermSetInfo = await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72")(); -``` - -### Add - -_Added in 3.10.0_ - -Allows you to add a term set. - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -// when adding a set directly from the root .sets property, you must include the "parentGroup" property -const setInfo = await sp.termStore.sets.add({ - parentGroup: { - id: "338666a8-1111-2222-3333-f72471314e72" - }, - contact: "steve", - description: "description", - isAvailableForTagging: true, - isOpen: true, - localizedNames: [{ - name: "MySet", - languageTag: "en-US", - }], - properties: [{ - key: "key1", - value: "value1", - }] -}); - -// when adding a termset through a group's sets property you do not specify the "parentGroup" property -const setInfo2 = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.add({ - contact: "steve", - description: "description", - isAvailableForTagging: true, - isOpen: true, - localizedNames: [{ - name: "MySet2", - languageTag: "en-US", - }], - properties: [{ - key: "key1", - value: "value1", - }] -}); -``` - -### getAllChildrenAsOrderedTree - -This method will get all of a set's child terms in an ordered array. It is a costly method in terms of requests so we suggest you cache the results as taxonomy trees seldom change. - -> Starting with version 2.6.0 you can now include an optional param to retrieve all of the term's properties and localProperties in the tree. Default is false. - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermInfo } from "@pnp/sp/taxonomy"; -import { dateAdd, PnPClientStorage } from "@pnp/core"; - -const sp = spfi(...); - -// here we get all the children of a given set -const childTree = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getAllChildrenAsOrderedTree(); - -// here we show caching the results using the PnPClientStorage class, there are many caching libraries and options available -const store = new PnPClientStorage(); - -// our tree likely doesn't change much in 30 minutes for most applications -// adjust to be longer or shorter as needed -const cachedTree = await store.local.getOrPut("myKey", () => { - return sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getAllChildrenAsOrderedTree(); -}, dateAdd(new Date(), "minute", 30)); - -// you can also get all the properties and localProperties -const set = sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72"); -const childTree = await set.getAllChildrenAsOrderedTree({ retrieveProperties: true }); -``` - -## TermSet - -Access term set information - -### Update - -_Added in 3.10.0_ - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -const termSetInfo = await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").update({ - properties: [{ - key: "MyKey2", - value: "MyValue2", - }], -}); - -const termSetInfo2 = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").update({ - properties: [{ - key: "MyKey3", - value: "MyValue3", - }], -}); -``` - -### Delete - -_Added in 3.10.0_ - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermGroupInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").delete(); - -await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").delete(); -``` - -## Terms - -Access term set information - -### List - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// list all the terms that are direct children of this set -const infos: ITermInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children(); -``` - -### List (terms) - -You can use the terms property to get a flat list of all terms in the set. These terms do not contain parent/child relationship information. - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// list all the terms available in this term set by group id then by term set id -const infos: ITermInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").terms(); - -// list all the terms available in this term set by term set id -const infosByTermSetId: ITermInfo[] = await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").terms(); -``` - -### Get By Id - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermInfo } from "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get term set data -const info: ITermInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72")(); -``` - -### Add - -_Added in 3.10.0_ - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; -import { ITermInfo } from "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -const newTermInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children.add({ - labels: [ - { - isDefault: true, - languageTag: "en-us", - name: "New Term", - } - ] -}); - -const newTermInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children.add({ - labels: [ - { - isDefault: true, - languageTag: "en-us", - name: "New Term 2", - } - ] -}); -``` - -## Term - -### Update - -> Note that when updating a Term if you update the `properties` it replaces the collection, so a merge of existing + new needs to be handled by your application. - -_Added in 3.10.0_ - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -const termInfo = await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").update({ - properties: [{ - key: "something", - value: "a value 2", - }], -}); - -const termInfo2 = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").update({ - properties: [{ - key: "something", - value: "a value", - }], -}); -``` - -### Delete - -_Added in 3.10.0_ - -```TypeScript -import { spfi, SPFxToken, SPFx } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; - -// NOTE: Because this endpoint requires a token and does not work with cookie auth you must create an instance of SPFI that includes an auth token. -// We've included a new behavior to support getting a token for sharepoint called `SPFxToken` -const sp = spfi().using(SPFx(context), SPFxToken(context)); - -const termInfo = await sp.termStore.sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").delete(); - -const termInfo2 = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72").delete(); -``` - -## Get Term Parent - -_Behavior Change in 2.1.0_ - -The server API changed again, resulting in the removal of the "parent" property from ITerm as it is not longer supported as a path property. You now must use "expand" to load a term's parent information. The side affect of this is that the parent is no longer chainable, meaning you need to load a new term instance to work with the parent term. An approach for this is shown below. - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/taxonomy"; - -const sp = spfi(...); - -// get a ref to the set -const set = sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72"); - -// get a term's information and expand parent to get the parent info as well -const w = await set.getTermById("338666a8-1111-2222-3333-f72471314e72").expand("parent")(); - -// get a ref to the parent term -const parent = set.getTermById(w.parent.id); - -// make a request for the parent term's info - this data currently match the results in the expand call above, but this -// is to demonstrate how to gain a ref to the parent and select its data -const parentInfo = await parent.select("Id", "Descriptions")(); -``` diff --git a/packages/sp/taxonomy/index.ts b/packages/graph/taxonomy/index.ts similarity index 50% rename from packages/sp/taxonomy/index.ts rename to packages/graph/taxonomy/index.ts index 8d5700a42..4e1faffb8 100644 --- a/packages/sp/taxonomy/index.ts +++ b/packages/graph/taxonomy/index.ts @@ -1,50 +1,40 @@ -import { SPFI } from "../fi.js"; +import { GraphFI } from "../fi.js"; import { ITermStore, TermStore } from "./types.js"; +import { Endpoint } from "../behaviors/endpoint.js"; + +import "./sites.js"; export { ITermStore, TermStore, - ITaxonomyUserInfo, ITermGroup, - ITermGroupInfo, ITermGroups, - ITermSetInfo, ITermSets, - ITermStoreInfo, TermGroup, TermGroups, TermSets, - ITaxonomyProperty, - ITermInfo, ITermSet, TermSet, - // IRelation, - IRelationInfo, - IRelations, + ITerms, + Terms, ITerm, - // Relation, - Relations, Term, + Relations, + IRelations, Children, IChildren, - IOrderedTermInfo, - ITermSortOrderInfo, - ITerms, - Terms, - IGetOrderedTreeProps, - ITaxonomyLocalProperty, } from "./types.js"; declare module "../fi" { - interface SPFI { + interface GraphFI { readonly termStore: ITermStore; } } -Reflect.defineProperty(SPFI.prototype, "termStore", { +Reflect.defineProperty(GraphFI.prototype, "termStore", { configurable: true, enumerable: true, - get: function (this: SPFI) { - return this.create(TermStore); + get: function (this: GraphFI) { + return this.create(TermStore, "termStore").using(Endpoint("beta")); }, }); diff --git a/packages/graph/taxonomy/sites.ts b/packages/graph/taxonomy/sites.ts new file mode 100644 index 000000000..fd1340f26 --- /dev/null +++ b/packages/graph/taxonomy/sites.ts @@ -0,0 +1,13 @@ +import { addProp } from "@pnp/queryable"; +import { _Site } from "../sites/types.js"; +import { ITermStore, TermStore } from "./types.js"; + +declare module "../sites/types" { + interface _Site { + readonly termStore: ITermStore; + } + interface ISite { + readonly termStore: ITermStore; + } +} +addProp(_Site, "termStore", TermStore); diff --git a/packages/graph/taxonomy/types.ts b/packages/graph/taxonomy/types.ts new file mode 100644 index 000000000..5ed609e09 --- /dev/null +++ b/packages/graph/taxonomy/types.ts @@ -0,0 +1,124 @@ +import { IAddable, IDeleteable, IGetById, IUpdateable, addable, defaultPath, deleteable, getById, updateable } from "../../graph/decorators.js"; +import { _GraphInstance, graphInvokableFactory, _GraphCollection } from "../graphqueryable.js"; +import { TermStore as ITermStoreType } from "@microsoft/microsoft-graph-types"; + +/** + * Describes a collection of Form objects + * + */ +@defaultPath("termstore") +@updateable() +export class _TermStore extends _GraphInstance { + + /** + * Gets the term groups associated with this tenant + */ + public get groups(): ITermGroups { + return TermGroups(this); + } + + /** + * Gets the term sets associated with this tenant + */ + public get sets(): ITermSets { + return TermSets(this); + } +} + +export interface ITermStore extends _TermStore, IUpdateable>> { } +export const TermStore = graphInvokableFactory(_TermStore); + +@deleteable() +export class _TermGroup extends _GraphInstance { + + /** + * Gets the term sets associated with this tenant + */ + public get sets(): ITermSets { + return TermSets(this, "sets"); + } +} +export interface ITermGroup extends _TermGroup, IDeleteable { } +export const TermGroup = graphInvokableFactory(_TermGroup); + + +@defaultPath("groups") +@getById(TermGroup) +@addable() +export class _TermGroups extends _GraphCollection { } +export interface ITermGroups extends _TermGroups, IAddable, IGetById { } +export const TermGroups = graphInvokableFactory(_TermGroups); + +@deleteable() +@updateable() +export class _TermSet extends _GraphInstance { + + /** + * Gets all the terms in this set + */ + public get terms(): ITerms { + return Terms(this); + } + + public get parentGroup(): ITermGroup { + return TermGroup(this, "parentGroup"); + } + + public get children(): IChildren { + return Children(this); + } + + public get relations(): IRelations { + return Relations(this); + } + + public getTermById(id: string): ITerm { + return Term(this, `terms/${id}`); + } +} +export interface ITermSet extends _TermSet, IUpdateable, IDeleteable { } +export const TermSet = graphInvokableFactory(_TermSet); + +@defaultPath("sets") +@getById(TermSet) +@addable() +export class _TermSets extends _GraphCollection { } +export interface ITermSets extends _TermSets, IAddable>, IGetById { } +export const TermSets = graphInvokableFactory(_TermSets); + +@defaultPath("children") +@addable() +export class _Children extends _GraphCollection { } +export interface IChildren extends _Children, IAddable> { } +export const Children = graphInvokableFactory(_Children); + +@updateable() +@deleteable() +export class _Term extends _GraphInstance { + + public get children(): IChildren { + return Children(this); + } + + public get relations(): IRelations { + return Relations(this); + } + + public get set(): ITermSet { + return TermSet(this, "set"); + } +} +export interface ITerm extends _Term, IUpdateable>>, IDeleteable { } +export const Term = graphInvokableFactory(_Term); + +@defaultPath("terms") +@getById(Term) +export class _Terms extends _GraphCollection { } +export interface ITerms extends _Terms, IGetById { } +export const Terms = graphInvokableFactory(_Terms); + +@defaultPath("relations") +@addable() +export class _Relations extends _GraphCollection { } +export interface IRelations extends _Relations, IAddable> { } +export const Relations = graphInvokableFactory(_Relations); diff --git a/packages/sp/presets/all.ts b/packages/sp/presets/all.ts index 521e74de1..c1fb87c74 100644 --- a/packages/sp/presets/all.ts +++ b/packages/sp/presets/all.ts @@ -29,7 +29,6 @@ import "../sites/index.js"; import "../social/index.js"; import "../sputilities/index.js"; import "../subscriptions/index.js"; -import "../taxonomy/index.js"; import "../user-custom-actions/index.js"; import "../views/index.js"; import "../webparts/index.js"; @@ -67,7 +66,6 @@ export * from "../sites/index.js"; export * from "../social/index.js"; export * from "../sputilities/index.js"; export * from "../subscriptions/index.js"; -export * from "../taxonomy/index.js"; export * from "../user-custom-actions/index.js"; export * from "../views/index.js"; export * from "../webparts/index.js"; diff --git a/packages/sp/taxonomy/types.ts b/packages/sp/taxonomy/types.ts deleted file mode 100644 index 219fa49e8..000000000 --- a/packages/sp/taxonomy/types.ts +++ /dev/null @@ -1,507 +0,0 @@ -import { isArray } from "@pnp/core"; -import { body } from "@pnp/queryable"; -import { defaultPath } from "../decorators.js"; -import { _SPInstance, spInvokableFactory, _SPCollection, spDelete, spPatch, spPost } from "../spqueryable.js"; -import { encodePath } from "../utils/encode-path-str.js"; - -/** - * Describes a collection of Form objects - * - */ -@defaultPath("_api/v2.1/termstore") -export class _TermStore extends _SPInstance { - - /** - * Gets the term groups associated with this tenant - */ - public get groups(): ITermGroups { - return TermGroups(this); - } - - /** - * Gets the term sets associated with this tenant - */ - public get sets(): ITermSets { - return TermSets(this); - } - - /** - * Allows you to locate terms within the termStore - * - * @param params Search parameters used to locate the terms, label is required - * @returns Array of terms including set information for each term - */ - public async searchTerm(params: ISearchTermParams): Promise>[]> { - - const query = Reflect.ownKeys(params).reduce((c, prop: string) => { - c.push(`${prop}='${encodePath(params[prop])}'`); - return c; - }, []).join(","); - - return TermStore(this, `searchTerm(${query})`).expand("set")(); - } - - /** - * Update settings for TermStore - * - * @param props The set or properties to update - * @returns The updated term store information - */ - public update(props: Partial>): Promise { - - return spPatch(this, body(props)); - } -} -export interface ITermStore extends _TermStore { } -export const TermStore = spInvokableFactory(_TermStore); - -@defaultPath("groups") -export class _TermGroups extends _SPCollection { - - /** - * Gets a term group by id - * - * @param id Id of the term group to access - */ - public getById(id: string): ITermGroup { - return TermGroup(this, id); - } - - /** - * Adds a new term group to this store - * @param props The set of properties - * @returns The information on the create group - */ - public add(props: Partial>): Promise { - - return spPost(this, body(props)); - } -} -export interface ITermGroups extends _TermGroups { } -export const TermGroups = spInvokableFactory(_TermGroups); - -export class _TermGroup extends _SPInstance { - - /** - * Gets the term sets associated with this tenant - */ - public get sets(): ITermSets { - return TermSets(this, "sets"); - } - - /** - * Deletes this group - * - * @returns void - */ - public delete(): Promise { - return spDelete(this); - } -} -export interface ITermGroup extends _TermGroup { } -export const TermGroup = spInvokableFactory(_TermGroup); - - -@defaultPath("sets") -export class _TermSets extends _SPCollection { - - /** - * Gets a term group by id - * - * @param id Id of the term group to access - */ - public getById(id: string): ITermSet { - return TermSet(this, id); - } - - /** - * Adds a new term set to this collection - * @param props The set of properties - * @returns The information on the created set - */ - public add(props: Partial): Promise { - return spPost(this, body(props)); - } -} -export interface ITermSets extends _TermSets { } -export const TermSets = spInvokableFactory(_TermSets); - -export class _TermSet extends _SPInstance { - - /** - * Gets all the terms in this set - */ - public get terms(): ITerms { - return Terms(this); - } - - public get parentGroup(): ITermGroup { - return TermGroup(this, "parentGroup"); - } - - public get children(): IChildren { - return Children(this); - } - - public get relations(): IRelations { - return Relations(this); - } - - public getTermById(id: string): ITerm { - return Term(this, `terms/${id}`); - } - - /** - * Update settings for TermSet - * - * @param props The set or properties to update - * @returns The updated term set information - */ - public update(props: Partial>): Promise { - - return spPatch(this, body(props)); - } - - /** - * Deletes this group - * - * @returns void - */ - public delete(): Promise { - return spDelete(this); - } - - /** - * Gets all the terms in this termset in an ordered tree using the appropriate sort ordering - * ** This is an expensive operation and you should strongly consider caching the results ** - * - * @param props Optional set of properties controlling how the tree is retrieved. - */ - public async getAllChildrenAsOrderedTree(props: Partial = {}): Promise { - - const selects = ["*", "customSortOrder"]; - if (props.retrieveProperties) { - selects.push("properties", "localProperties"); - } - - const setInfo = await this.select(...selects)(); - const tree: IOrderedTermInfo[] = []; - const childIds = []; - - const ensureOrder = (terms: IOrderedTermInfo[], sorts: ITermSortOrderInfo[], setSorts?: string[]): IOrderedTermInfo[] => { - - // handle no custom sort information present - if (!isArray(sorts) && !isArray(setSorts)) { - return terms; - } - - let ordering: string[] = null; - if (sorts === null && setSorts.length > 0) { - ordering = [...setSorts]; - } else { - const index = sorts.findIndex(v => v.setId === setInfo.id); - if (index >= 0) { - ordering = [...sorts[index].order]; - } - } - - if (ordering !== null) { - const orderedChildren = []; - ordering.forEach(o => { - const found = terms.find(ch => o === ch.id); - if (found) { - orderedChildren.push(found); - } - }); - // we have a case where if a set is ordered and a term is added to that set - // AND the ordering information hasn't been updated in the UI the new term will not have - // any associated ordering information. See #1547 which reported this. So here we - // append any terms remaining in "terms" not in "orderedChildren" to the end of "orderedChildren" - orderedChildren.push(...terms.filter(info => ordering.indexOf(info.id) < 0)); - - return orderedChildren; - } - return terms; - }; - - const visitor = async (source: any, parent: IOrderedTermInfo[]) => { - - const children = await source(); - - for (let i = 0; i < children.length; i++) { - - const child = children[i]; - childIds.push(child.id); - - const orderedTerm: Partial = { - children: [], - defaultLabel: child.labels.find(l => l.isDefault).name, - ...child, - }; - - if (child.childrenCount > 0) { - await visitor(this.getTermById(children[i].id).children.select(...selects), orderedTerm.children); - orderedTerm.children = ensureOrder(orderedTerm.children, child.customSortOrder); - } - - parent.push(>orderedTerm); - } - }; - - // There is a series of issues where users expect that copied terms appear in the result of this method call. Copied terms are not "children" so we need - // to get all the children + all the "/terms" and filter out the children. This is expensive but this method call is already indicated to be used with caching - await visitor(this.children.select(...selects), tree); - await visitor(async () => { - - const terms = await Terms(this).select(...selects)(); - return terms.filter((t) => childIds.indexOf(t.id) < 0); - - }, tree); - - return ensureOrder(tree, null, setInfo.customSortOrder); - } -} -export interface ITermSet extends _TermSet { } -export const TermSet = spInvokableFactory(_TermSet); - -@defaultPath("children") -export class _Children extends _SPCollection { - /** - * Adds a new term set to this collection - * @param props The set of properties - * @returns The information on the create group - */ - public add(props: Pick): Promise { - - return spPost(this, body(props)); - } -} -export interface IChildren extends _Children { } -export const Children = spInvokableFactory(_Children); - -@defaultPath("terms") -export class _Terms extends _SPCollection { - /** - * Gets a term group by id - * - * @param id Id of the term group to access - */ - public getById(id: string): ITerm { - return Term(this, id); - } -} -export interface ITerms extends _Terms { } -export const Terms = spInvokableFactory(_Terms); - -export class _Term extends _SPInstance { - - public get children(): IChildren { - return Children(this); - } - - public get relations(): IRelations { - return Relations(this); - } - - public get set(): ITermSet { - return TermSet(this, "set"); - } - - /** - * Update settings for TermSet - * - * @param props The set or properties to update - * @returns The updated term set information - */ - public update(props: Partial>): Promise { - - return spPatch(this, body(props)); - } - - /** - * Deletes this group - * - * @returns void - */ - public delete(): Promise { - return spDelete(this); - } -} -export interface ITerm extends _Term { } -export const Term = spInvokableFactory(_Term); - - -@defaultPath("relations") -export class _Relations extends _SPCollection { - /** - * Adds a new relation to this term - * @param props The set of properties - * @returns The information on the created relation - */ - public add(props: Omit): Promise { - - return spPost(this, body(props)); - } -} -export interface IRelations extends _Relations { } -export const Relations = spInvokableFactory(_Relations); - -// export class _Relation extends _SPInstance { - -// public get fromTerm(): ITerm { -// return Term(this, "fromTerm"); -// } - -// public get toTerm(): ITerm { -// return Term(this, "toTerm"); -// } - -// public get set(): ITermSet { -// return TermSet(this, "set"); -// } -// } -// export interface IRelation extends _Relation { } -// export const Relation = spInvokableFactory(_Relation); - -export interface ITermStoreInfo { - id: string; - name: string; - defaultLanguageTag: string; - languageTags: string[]; - administrators?: ITaxonomyUserInfo; -} - -export interface ITermGroupInfo { - id: string; - description: string; - name: string; - displayName: string; - createdDateTime: string; - lastModifiedDateTime: string; - type: string; - scope: "global" | "system" | "siteCollection"; -} - -export interface ITermSetInfo { - id: string; - localizedNames: { name: string; languageTag: string }[]; - description: string; - createdDateTime: string; - customSortOrder: string[]; - properties?: ITaxonomyProperty[]; - childrenCount: number; - groupId: string; - isOpen: boolean; - isAvailableForTagging: boolean; - contact: string; -} - -export interface ITermSetCreateParams { - localizedNames: { name: string; languageTag: string }[]; - description?: string; - properties?: ITaxonomyProperty[]; - /** - * When adding a term set using ITermStore.sets parentGroup is required, when adding from ITermGroup.sets parentGroup is not needed - */ - parentGroup?: { - id: string; - }; - isOpen?: boolean; - isAvailableForTagging?: boolean; - contact?: string; -} - -export interface ITermInfo { - childrenCount: number; - id: string; - labels: { name: string; isDefault: boolean; languageTag: string }[]; - createdDateTime: string; - customSortOrder?: ITermSortOrderInfo[]; - lastModifiedDateTime: string; - descriptions: { description: string; languageTag: string }[]; - properties?: ITaxonomyProperty[]; - localProperties?: ITaxonomyLocalProperty[]; - isDeprecated: boolean; - isAvailableForTagging: { setId: string; isAvailable: boolean }[]; - topicRequested?: boolean; - parent?: ITermInfo; - set?: ITermSetInfo; - relations?: IRelationInfo[]; - children?: ITermInfo[]; -} - -export interface ISearchTermParams { - /** - * The term label to search for. - */ - label: string; - /** - * The setId to scope down the search under a termSet. - */ - setId?: string; - /** - * The parentTermId to scope down the search under a termSet, under a parent term. - */ - parentTermId?: string; - /** - * The languageTag to scope down the search to a specific language. - */ - languageTag?: string; - /** - * Indicates what type of string matching should be performed when searching. - */ - stringMatchOption?: "ExactMatch" | "StartsWith"; -} - -type SearchTermPickedProps = "childrenCount" | "createdDateTime" | "descriptions" | "id" | "isAvailableForTagging" | "isDeprecated" | "labels" | "lastModifiedDateTime" | "set"; - -export interface ITermSortOrderInfo { - setId: string; - order: string[]; -} - -export interface IOrderedTermInfo extends ITermInfo { - children: ITermInfo[]; - defaultLabel: string; -} - -export interface IRelationInfo { - id: string; - relationType: string; -} - -export interface IRelationCreateInfo { - id: string; - relationship: "pin" | "reuse"; - fromTerm: { - id: string; - }; - toTerm: { - id: string; - }; - set: { - id: string; - }; -} - -export interface ITaxonomyUserInfo { - user: { - displayName: string; - email: string; - id: string; - }; -} - -export interface ITaxonomyProperty { - key: string; - value: string; -} - -export interface ITaxonomyLocalProperty { - setId: string; - properties: ITaxonomyProperty[]; -} - -export interface IGetOrderedTreeProps { - retrieveProperties: boolean; -} diff --git a/test/sp/taxonomy.ts b/test/graph/taxonomy.ts similarity index 69% rename from test/sp/taxonomy.ts rename to test/graph/taxonomy.ts index 9da671152..9099110c7 100644 --- a/test/sp/taxonomy.ts +++ b/test/graph/taxonomy.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; -import "@pnp/sp/taxonomy"; -import { ITermSet } from "@pnp/sp/taxonomy"; +import "@pnp/graph/sites"; +import "@pnp/graph/taxonomy"; +import { ITermSet } from "@pnp/graph/taxonomy"; describe("Taxonomy", function () { @@ -14,12 +15,12 @@ describe("Taxonomy", function () { describe("TermStore", function () { it("-invoke", async function () { - const info = await this.pnp.sp.termStore(); + const info = await this.pnp.graph.termStore(); return expect(info).has.property("id"); }); it("groups", async function () { - const info = await this.pnp.sp.termStore.groups(); + const info = await this.pnp.graph.termStore.groups(); if (info === undefined || info.length < 1) { return expect(info).to.be.an("Array"); @@ -30,9 +31,9 @@ describe("Taxonomy", function () { // TODO: sets gives API not found error on termStore... need to remove/or fix. it.skip(".sets", async function () { - const url = this.pnp.sp.termStore.sets.toRequestUrl(); + const url = this.pnp.graph.termStore.sets.toRequestUrl(); console.log(`Sets: ${url}`); - const info = await this.pnp.sp.termStore.sets(); + const info = await this.pnp.graph.termStore.sets(); if (info === undefined || info.length < 1) { return expect(info).to.be.an("Array"); } @@ -42,13 +43,13 @@ describe("Taxonomy", function () { it("groups.getById", async function () { - const info = await this.pnp.sp.termStore.groups(); + const info = await this.pnp.graph.termStore.groups(); if (info === undefined || info.length < 1) { return expect(info).to.be.an("Array"); } - const group = await this.pnp.sp.termStore.groups.getById(info[0].id)(); + const group = await this.pnp.graph.termStore.groups.getById(info[0].id)(); return expect(group).has.property("id"); }); @@ -56,13 +57,13 @@ describe("Taxonomy", function () { // TODO: sets gives API not found error on termStore... need to remove/or fix. it.skip(".sets.getById", async function () { - const info = await this.pnp.sp.termStore.sets(); + const info = await this.pnp.graph.termStore.sets(); if (info === undefined || info.length < 1) { return expect(info).to.be.an("Array"); } - const set = await this.pnp.sp.termStore.sets.getById(info[0].id)(); + const set = await this.pnp.graph.termStore.sets.getById(info[0].id)(); return expect(set).has.property("id"); }); }); @@ -73,19 +74,19 @@ describe("Taxonomy", function () { let termset: ITermSet = null; before(async function () { - const groups = await this.pnp.sp.termStore.groups(); + const groups = await this.pnp.graph.termStore.groups(); if (groups === undefined || groups?.length < 1) { this.skip(); } const groupId = groups[0].id; - const sets = await this.pnp.sp.termStore.groups.getById(groupId).sets(); + const sets = await this.pnp.graph.termStore.groups.getById(groupId).sets(); if (sets === undefined || sets?.length < 1) { this.skip(); } const termsetId = sets[0].id; - termset = this.pnp.sp.termStore.groups.getById(groupId).sets.getById(termsetId); + termset = this.pnp.graph.termStore.groups.getById(groupId).sets.getById(termsetId); }); it("terms", async function () { @@ -117,18 +118,6 @@ describe("Taxonomy", function () { const termById = await termset.getTermById(terms[0].id)(); return expect(termById).has.property("id"); }); - it("getAllChildrenAsOrderedTree", async function () { - const tree = await termset.getAllChildrenAsOrderedTree(); - return expect(tree).to.be.an("Array"); - }); - it("getAllChildrenAsOrderedTree-retreiveProperties", async function () { - const tree = await termset.getAllChildrenAsOrderedTree({ retrieveProperties: true }); - if (tree.length < 1) { - return; - } - const term = tree[0]; - return expect(term).has.property("localProperties"); - }); }); /** @@ -138,26 +127,26 @@ describe("Taxonomy", function () { let term = null; before(async function () { - const groups = await this.pnp.sp.termStore.groups(); + const groups = await this.pnp.graph.termStore.groups(); if (groups === undefined || groups?.length < 1) { this.skip(); } const groupId = groups[0].id; - const sets = await this.pnp.sp.termStore.groups.getById(groupId).sets(); + const sets = await this.pnp.graph.termStore.groups.getById(groupId).sets(); if (sets === undefined || sets?.length < 1) { this.skip(); } const setId = sets[0].id; - const terms = await this.pnp.sp.termStore.groups.getById(groupId).sets.getById(setId).terms(); + const terms = await this.pnp.graph.termStore.groups.getById(groupId).sets.getById(setId).terms(); if (terms === undefined || terms?.length < 1) { this.skip(); } const termId = terms[0].id; - term = this.pnp.sp.termStore.groups.getById(groupId).sets.getById(setId).terms.getById(termId); + term = this.pnp.graph.termStore.groups.getById(groupId).sets.getById(setId).terms.getById(termId); }); it("getById", async function () {