@kwiz/common 1.0.30 → 1.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1461,4 +1461,14 @@ export type IRententionLabel = {
1461
1461
  TagRetentionBasedOn: string;
1462
1462
  UnlockedAsDefault: boolean;
1463
1463
  };
1464
+ export type spNavLinkLocation = "quicklaunch" | "topnavigationbar" | "none";
1465
+ export interface INavLinkInfo {
1466
+ Id: number;
1467
+ IsDocLib: boolean;
1468
+ IsExternal: boolean;
1469
+ IsVisible: boolean;
1470
+ Title: string;
1471
+ Url: string;
1472
+ Location: spNavLinkLocation;
1473
+ }
1464
1474
  export {};
@@ -4,6 +4,7 @@ export * from './date';
4
4
  export * from './file.folder';
5
5
  export * from './item';
6
6
  export * from './list';
7
+ export * from './navigation-links';
7
8
  export * from './user-search';
8
9
  export * from './user';
9
10
  export * from './web';
@@ -20,6 +20,7 @@ __exportStar(require("./date"), exports);
20
20
  __exportStar(require("./file.folder"), exports);
21
21
  __exportStar(require("./item"), exports);
22
22
  __exportStar(require("./list"), exports);
23
+ __exportStar(require("./navigation-links"), exports);
23
24
  __exportStar(require("./user-search"), exports);
24
25
  __exportStar(require("./user"), exports);
25
26
  __exportStar(require("./web"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"exports-index.js","sourceRoot":"","sources":["../../../src/utils/sharepoint.rest/exports-index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,2CAAyB;AACzB,yCAAuB;AACvB,gDAA8B;AAC9B,yCAAuB;AACvB,yCAAuB;AACvB,gDAA8B;AAC9B,yCAAuB;AACvB,wCAAsB"}
1
+ {"version":3,"file":"exports-index.js","sourceRoot":"","sources":["../../../src/utils/sharepoint.rest/exports-index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,2CAAyB;AACzB,yCAAuB;AACvB,gDAA8B;AAC9B,yCAAuB;AACvB,yCAAuB;AACvB,qDAAmC;AACnC,gDAA8B;AAC9B,yCAAuB;AACvB,wCAAsB"}
@@ -0,0 +1,21 @@
1
+ import { INavLinkInfo } from "../_dependencies";
2
+ /**
3
+ * Get all navigation links in the top and side navigation of a SharePoint site
4
+ * @param siteUrl The URL of the SharePoint site
5
+ * @returns An array containing all navigation links
6
+ */
7
+ export declare function GetNavigationLinks(siteUrl?: string): Promise<INavLinkInfo[]>;
8
+ /**
9
+ * Add a navigation link to the specified location (top navigation or side navigation)
10
+ * @param title The title of the navigation link
11
+ * @param url The url of the navigation link
12
+ * @param location The location where the link will be added ('topnavigationbar' or 'quicklaunch'). Default is 'quicklaunch'.
13
+ * @Logs If the location is invalid or if adding the link fails
14
+ */
15
+ export declare function AddNavigationLink(location?: string): Promise<INavLinkInfo>;
16
+ /**
17
+ * Delete navigation links by title and URL
18
+ * @param navLinks An array of navigation links to be deleted
19
+ * @Logs If the location is invalid or if deleting the links fails
20
+ */
21
+ export declare function DeleteNavigationLinks(navLinks: INavLinkInfo[]): Promise<void>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeleteNavigationLinks = exports.AddNavigationLink = exports.GetNavigationLinks = void 0;
4
+ const _dependencies_1 = require("../_dependencies");
5
+ const consolelogger_1 = require("../consolelogger");
6
+ const rest_1 = require("../rest");
7
+ const common_1 = require("./common");
8
+ const logger = consolelogger_1.ConsoleLogger.get("SharePoint.Rest.Navigation-Links");
9
+ /**
10
+ * Get all navigation links in the top and side navigation of a SharePoint site
11
+ * @param siteUrl The URL of the SharePoint site
12
+ * @returns An array containing all navigation links
13
+ */
14
+ async function GetNavigationLinks(siteUrl) {
15
+ siteUrl = (0, common_1.GetSiteUrl)(siteUrl);
16
+ const topNavUrl = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/navigation/topnavigationbar`;
17
+ const sideNavUrl = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/navigation/quicklaunch`;
18
+ try {
19
+ const topNavResponse = await (0, rest_1.GetJson)(topNavUrl);
20
+ const sideNavResponse = await (0, rest_1.GetJson)(sideNavUrl);
21
+ const topNavLinks = topNavResponse.d.results.map((link) => ({ ...link, Location: "topnavigationbar" }));
22
+ const sideNavLinks = sideNavResponse.d.results.map((link) => ({ ...link, Location: "quicklaunch" }));
23
+ return [...topNavLinks, ...sideNavLinks];
24
+ }
25
+ catch (error) {
26
+ logger.error(`Error fetching navigation links: ${error.message}`);
27
+ }
28
+ return [];
29
+ }
30
+ exports.GetNavigationLinks = GetNavigationLinks;
31
+ /**
32
+ * Add a navigation link to the specified location (top navigation or side navigation)
33
+ * @param title The title of the navigation link
34
+ * @param url The url of the navigation link
35
+ * @param location The location where the link will be added ('topnavigationbar' or 'quicklaunch'). Default is 'quicklaunch'.
36
+ * @Logs If the location is invalid or if adding the link fails
37
+ */
38
+ async function AddNavigationLink(location = 'quicklaunch') {
39
+ try {
40
+ let siteUrl = (0, common_1.GetSiteUrl)();
41
+ let navigationUrl = "";
42
+ navigationUrl = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/navigation/${location}`;
43
+ const response = await (0, rest_1.GetJson)(navigationUrl, JSON.stringify({
44
+ '__metadata': { 'type': 'SP.NavigationNode' },
45
+ 'Title': "CMS365",
46
+ 'Url': `${(0, _dependencies_1.normalizeUrl)(siteUrl, true)}SitePages/cms365.aspx`
47
+ }), {
48
+ spWebUrl: siteUrl,
49
+ });
50
+ if (!(0, _dependencies_1.isNullOrUndefined)(response) && !(0, _dependencies_1.isNullOrUndefined)(response.d)) {
51
+ return response.d;
52
+ }
53
+ }
54
+ catch (error) {
55
+ logger.error('Error adding link');
56
+ }
57
+ }
58
+ exports.AddNavigationLink = AddNavigationLink;
59
+ /**
60
+ * Delete navigation links by title and URL
61
+ * @param navLinks An array of navigation links to be deleted
62
+ * @Logs If the location is invalid or if deleting the links fails
63
+ */
64
+ async function DeleteNavigationLinks(navLinks) {
65
+ try {
66
+ const siteUrl = (0, common_1.GetSiteUrl)();
67
+ for (const navLink of navLinks) {
68
+ const navigationUrl = `${(0, common_1.GetRestBaseUrl)(siteUrl)}/web/Navigation/GetNodeById(${navLink.Id})`;
69
+ // Use the same convention to make the DELETE request
70
+ const response = await (0, rest_1.GetJson)(navigationUrl, null, {
71
+ method: 'POST',
72
+ spWebUrl: siteUrl,
73
+ xHttpMethod: 'DELETE'
74
+ });
75
+ if (!(0, _dependencies_1.isNullOrEmptyString)(response) && !response.ok) {
76
+ logger.error('Failed to delete link');
77
+ }
78
+ }
79
+ logger.info('Navigation links deleted successfully');
80
+ }
81
+ catch (error) {
82
+ logger.error('Error deleting links');
83
+ }
84
+ }
85
+ exports.DeleteNavigationLinks = DeleteNavigationLinks;
86
+ //# sourceMappingURL=navigation-links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation-links.js","sourceRoot":"","sources":["../../../src/utils/sharepoint.rest/navigation-links.ts"],"names":[],"mappings":";;;AAAA,oDAAsG;AACtG,oDAAiD;AACjD,kCAAkC;AAClC,qCAAsD;AAEtD,MAAM,MAAM,GAAG,6BAAa,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAErE;;;;GAIG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAgB;IACrD,OAAO,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,GAAG,IAAA,uBAAc,EAAC,OAAO,CAAC,kCAAkC,CAAC;IAC/E,MAAM,UAAU,GAAG,GAAG,IAAA,uBAAc,EAAC,OAAO,CAAC,6BAA6B,CAAC;IAE3E,IAAI,CAAC;QACD,MAAM,cAAc,GAAG,MAAM,IAAA,cAAO,EAAqC,SAAS,CAAC,CAAC;QACpF,MAAM,eAAe,GAAG,MAAM,IAAA,cAAO,EAAqC,UAAU,CAAC,CAAC;QAEtF,MAAM,WAAW,GAAmB,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAkB,EAAE,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AAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACtC,CAAC;AACL,CAAC;AApBD,8CAoBC;AAED;;;;GAIG;AACI,KAAK,UAAU,qBAAqB,CAAC,QAAwB;IAChE,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC7B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC7B,MAAM,aAAa,GAAG,GAAG,IAAA,uBAAc,EAAC,OAAO,CAAC,+BAA+B,OAAO,CAAC,EAAE,GAAG,CAAC;YAC7F,qDAAqD;YACrD,MAAM,QAAQ,GAAG,MAAM,IAAA,cAAO,EAAM,aAAa,EAAE,IAAI,EAAE;gBACrD,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,OAAO;gBACjB,WAAW,EAAE,QAAQ;aACxB,CAAC,CAAC;YAEH,IAAI,CAAC,IAAA,mCAAmB,EAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjD,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC1C,CAAC;QACL,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACzC,CAAC;AACL,CAAC;AApBD,sDAoBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwiz/common",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "KWIZ common utilities and helpers for M365 platform",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1445,3 +1445,15 @@ export type IRententionLabel = {
1445
1445
  TagRetentionBasedOn: string;
1446
1446
  UnlockedAsDefault: boolean;
1447
1447
  }
1448
+
1449
+ export type spNavLinkLocation = "quicklaunch" | "topnavigationbar" | "none";
1450
+
1451
+ export interface INavLinkInfo {
1452
+ Id: number;
1453
+ IsDocLib: boolean;
1454
+ IsExternal: boolean;
1455
+ IsVisible: boolean;
1456
+ Title: string;
1457
+ Url: string;
1458
+ Location: spNavLinkLocation;
1459
+ }
@@ -4,6 +4,7 @@ export * from './date';
4
4
  export * from './file.folder';
5
5
  export * from './item';
6
6
  export * from './list';
7
+ export * from './navigation-links';
7
8
  export * from './user-search';
8
9
  export * from './user';
9
10
  export * from './web';
@@ -0,0 +1,86 @@
1
+ import { INavLinkInfo, isNullOrEmptyString, isNullOrUndefined, normalizeUrl } from "../_dependencies";
2
+ import { ConsoleLogger } from "../consolelogger";
3
+ import { GetJson } from "../rest";
4
+ import { GetRestBaseUrl, GetSiteUrl } from "./common";
5
+
6
+ const logger = ConsoleLogger.get("SharePoint.Rest.Navigation-Links");
7
+
8
+ /**
9
+ * Get all navigation links in the top and side navigation of a SharePoint site
10
+ * @param siteUrl The URL of the SharePoint site
11
+ * @returns An array containing all navigation links
12
+ */
13
+ export async function GetNavigationLinks(siteUrl?: string): Promise<INavLinkInfo[]> {
14
+ siteUrl = GetSiteUrl(siteUrl);
15
+ const topNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/topnavigationbar`;
16
+ const sideNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/quicklaunch`;
17
+
18
+ try {
19
+ const topNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(topNavUrl);
20
+ const sideNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(sideNavUrl);
21
+
22
+ const topNavLinks: INavLinkInfo[] = topNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "topnavigationbar" }));
23
+ const sideNavLinks: INavLinkInfo[] = sideNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "quicklaunch" }));
24
+
25
+ return [...topNavLinks, ...sideNavLinks];
26
+ } catch (error) {
27
+ logger.error(`Error fetching navigation links: ${error.message}`);
28
+ }
29
+ return [];
30
+ }
31
+
32
+ /**
33
+ * Add a navigation link to the specified location (top navigation or side navigation)
34
+ * @param title The title of the navigation link
35
+ * @param url The url of the navigation link
36
+ * @param location The location where the link will be added ('topnavigationbar' or 'quicklaunch'). Default is 'quicklaunch'.
37
+ * @Logs If the location is invalid or if adding the link fails
38
+ */
39
+ export async function AddNavigationLink(location: string = 'quicklaunch'): Promise<INavLinkInfo> {
40
+ try {
41
+ let siteUrl = GetSiteUrl();
42
+ let navigationUrl = "";
43
+ navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/${location}`;
44
+ const response = await GetJson<{ d: INavLinkInfo }>(navigationUrl, JSON.stringify({
45
+ '__metadata': { 'type': 'SP.NavigationNode' },
46
+ 'Title': "CMS365",
47
+ 'Url': `${normalizeUrl(siteUrl, true)}SitePages/cms365.aspx`
48
+ }), {
49
+ spWebUrl: siteUrl,
50
+ });
51
+
52
+
53
+ if (!isNullOrUndefined(response) && !isNullOrUndefined(response.d)) {
54
+ return response.d;
55
+ }
56
+ } catch (error) {
57
+ logger.error('Error adding link');
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Delete navigation links by title and URL
63
+ * @param navLinks An array of navigation links to be deleted
64
+ * @Logs If the location is invalid or if deleting the links fails
65
+ */
66
+ export async function DeleteNavigationLinks(navLinks: INavLinkInfo[]): Promise<void> {
67
+ try {
68
+ const siteUrl = GetSiteUrl();
69
+ for (const navLink of navLinks) {
70
+ const navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/Navigation/GetNodeById(${navLink.Id})`;
71
+ // Use the same convention to make the DELETE request
72
+ const response = await GetJson<any>(navigationUrl, null, {
73
+ method: 'POST',
74
+ spWebUrl: siteUrl,
75
+ xHttpMethod: 'DELETE'
76
+ });
77
+
78
+ if (!isNullOrEmptyString(response) && !response.ok) {
79
+ logger.error('Failed to delete link');
80
+ }
81
+ }
82
+ logger.info('Navigation links deleted successfully');
83
+ } catch (error) {
84
+ logger.error('Error deleting links');
85
+ }
86
+ }