@kwiz/common 1.0.78 → 1.0.79

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.
Files changed (113) hide show
  1. package/.github/workflows/npm-publish.yml +24 -0
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/helpers/sharepoint.js +5 -1
  6. package/lib/cjs/helpers/sharepoint.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/utils/sharepoint.rest/list.js +1 -1
  9. package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
  10. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  11. package/lib/esm/helpers/sharepoint.js +3 -0
  12. package/lib/esm/helpers/sharepoint.js.map +1 -1
  13. package/lib/esm/types/libs/msal.types.js +26 -26
  14. package/lib/esm/utils/sharepoint.rest/list.js +2 -2
  15. package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
  16. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  17. package/lib/types/helpers/sharepoint.d.ts +1 -0
  18. package/package.json +77 -77
  19. package/readme.md +17 -17
  20. package/src/_dependencies.ts +12 -12
  21. package/src/config.ts +17 -17
  22. package/src/helpers/Guid.ts +181 -181
  23. package/src/helpers/base64.ts +173 -173
  24. package/src/helpers/browser.test.js +13 -13
  25. package/src/helpers/browser.ts +1348 -1348
  26. package/src/helpers/browserinfo.ts +292 -292
  27. package/src/helpers/collections.base.test.js +25 -25
  28. package/src/helpers/collections.base.ts +437 -437
  29. package/src/helpers/collections.ts +107 -107
  30. package/src/helpers/color.ts +54 -54
  31. package/src/helpers/cookies.ts +59 -59
  32. package/src/helpers/date.test.js +119 -119
  33. package/src/helpers/date.ts +188 -188
  34. package/src/helpers/debug.ts +186 -186
  35. package/src/helpers/emails.ts +6 -6
  36. package/src/helpers/eval.ts +5 -5
  37. package/src/helpers/file.test.js +50 -50
  38. package/src/helpers/file.ts +58 -58
  39. package/src/helpers/flatted.ts +149 -149
  40. package/src/helpers/functions.ts +16 -16
  41. package/src/helpers/graph/calendar.types.ts +10 -10
  42. package/src/helpers/http.ts +69 -69
  43. package/src/helpers/images.ts +22 -22
  44. package/src/helpers/json.ts +38 -38
  45. package/src/helpers/md5.ts +189 -189
  46. package/src/helpers/objects.test.js +33 -33
  47. package/src/helpers/objects.ts +270 -270
  48. package/src/helpers/promises.test.js +37 -37
  49. package/src/helpers/promises.ts +165 -165
  50. package/src/helpers/random.ts +27 -27
  51. package/src/helpers/scheduler/scheduler.test.js +103 -103
  52. package/src/helpers/scheduler/scheduler.ts +131 -131
  53. package/src/helpers/sharepoint.ts +776 -772
  54. package/src/helpers/strings.test.js +101 -101
  55. package/src/helpers/strings.ts +317 -317
  56. package/src/helpers/typecheckers.test.js +34 -34
  57. package/src/helpers/typecheckers.ts +262 -262
  58. package/src/helpers/url.test.js +43 -43
  59. package/src/helpers/url.ts +207 -207
  60. package/src/helpers/urlhelper.ts +111 -111
  61. package/src/index.ts +6 -6
  62. package/src/types/auth.ts +54 -54
  63. package/src/types/common.types.ts +15 -15
  64. package/src/types/flatted.types.ts +59 -59
  65. package/src/types/globals.types.ts +6 -6
  66. package/src/types/graph/calendar.types.ts +80 -80
  67. package/src/types/knownscript.types.ts +18 -18
  68. package/src/types/libs/datajs.types.ts +28 -28
  69. package/src/types/libs/ics.types.ts +30 -30
  70. package/src/types/libs/msal.types.ts +49 -49
  71. package/src/types/locales.ts +124 -124
  72. package/src/types/localstoragecache.types.ts +8 -8
  73. package/src/types/location.types.ts +27 -27
  74. package/src/types/moment.ts +11 -11
  75. package/src/types/regex.types.ts +16 -16
  76. package/src/types/rest.types.ts +95 -95
  77. package/src/types/sharepoint.types.ts +1465 -1465
  78. package/src/types/sharepoint.utils.types.ts +287 -287
  79. package/src/utils/auth/common.ts +74 -74
  80. package/src/utils/auth/discovery.test.js +12 -12
  81. package/src/utils/auth/discovery.ts +132 -132
  82. package/src/utils/base64.ts +27 -27
  83. package/src/utils/consolelogger.ts +320 -320
  84. package/src/utils/date.ts +35 -35
  85. package/src/utils/emails.ts +24 -24
  86. package/src/utils/knownscript.ts +286 -286
  87. package/src/utils/localstoragecache.ts +441 -441
  88. package/src/utils/rest.ts +501 -501
  89. package/src/utils/script.ts +170 -170
  90. package/src/utils/sharepoint.rest/common.ts +154 -154
  91. package/src/utils/sharepoint.rest/date.ts +62 -62
  92. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  93. package/src/utils/sharepoint.rest/item.ts +547 -547
  94. package/src/utils/sharepoint.rest/list.ts +1388 -1388
  95. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  96. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  97. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  98. package/src/utils/sharepoint.rest/location.ts +141 -141
  99. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  100. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  101. package/src/utils/sharepoint.rest/user.ts +491 -491
  102. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  103. package/src/utils/sod.ts +194 -194
  104. package/lib/cjs/helpers/_dependencies.js +0 -21
  105. package/lib/cjs/helpers/_dependencies.js.map +0 -1
  106. package/lib/cjs/utils/_dependencies.js +0 -24
  107. package/lib/cjs/utils/_dependencies.js.map +0 -1
  108. package/lib/esm/helpers/_dependencies.js +0 -3
  109. package/lib/esm/helpers/_dependencies.js.map +0 -1
  110. package/lib/esm/utils/_dependencies.js +0 -4
  111. package/lib/esm/utils/_dependencies.js.map +0 -1
  112. package/lib/types/helpers/_dependencies.d.ts +0 -2
  113. package/lib/types/utils/_dependencies.d.ts +0 -3
@@ -1,142 +1,142 @@
1
- import { waitFor } from "../../helpers/browser";
2
- import { isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isTypeofFullNameUndefined } from "../../helpers/typecheckers";
3
- import { SPFxAuthTokenType } from "../../types/auth";
4
- import { IMeetingLocation, IMeetingLocationEntityType } from "../../types/location.types";
5
- import { jsonTypes } from "../../types/rest.types";
6
- import { GetSPFxClientAuthToken } from "../auth/common";
7
- import { GetJson, shortLocalCache } from "../rest";
8
-
9
- interface IMeetingLocationsQuery {
10
- QueryConstraint: {
11
- Query: string;
12
- Id?: string;
13
- ResolveAvailability?: boolean;
14
- };
15
- LocationProvider: 32 | 8;
16
- BingMarket?: string;
17
- }
18
-
19
- interface IMeetingLocationResult {
20
- LocationType: IMeetingLocationEntityType
21
- RelevanceHint: string;
22
- RelevanceScore: number;
23
- MeetingLocation: IMeetingLocation;
24
- }
25
-
26
- interface IMeetingLocationsResponse {
27
- MeetingLocations: IMeetingLocationResult[],
28
- EmptyLocationsHint: string;
29
- }
30
-
31
- async function _findMeetingLocations(options: { bingUri: string; query: string }) {
32
- if (isNullOrUndefined(options) || (isNullOrEmptyString(options.bingUri) && isNullOrEmptyString(options.query))) {
33
- return null;
34
- }
35
-
36
- let contextReady = await waitFor(() => {
37
- return !isTypeofFullNameUndefined("_spPageContextInfo");
38
- });
39
-
40
- if (!contextReady) {
41
- return null;
42
- }
43
-
44
- let authToken = await GetSPFxClientAuthToken(_spPageContextInfo.webServerRelativeUrl, SPFxAuthTokenType.Outlook);
45
-
46
- if (isNullOrEmptyString(authToken)) {
47
- return null;
48
- }
49
-
50
- const { query, bingUri } = options;
51
-
52
- let useBingUri = !isNullOrEmptyString(bingUri);
53
-
54
- let queryData: IMeetingLocationsQuery = {
55
- QueryConstraint: {
56
- Query: useBingUri === true ? "" : query,
57
- Id: useBingUri === true ? bingUri : undefined,
58
- ResolveAvailability: useBingUri === true ? false : undefined
59
- },
60
- LocationProvider: useBingUri ? 8 : 32,
61
- BingMarket: _spPageContextInfo.currentCultureName
62
- };
63
-
64
- let url = "https://outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations";
65
- let result = await GetJson<IMeetingLocationsResponse>(
66
- url,
67
- JSON.stringify(queryData),
68
- {
69
- ...shortLocalCache,
70
- postCacheKey: `${queryData.BingMarket}|${queryData.LocationProvider}|${useBingUri ? queryData.QueryConstraint.Id : queryData.QueryConstraint.Query}`,
71
- includeDigestInPost: false,
72
- headers: {
73
- "Accept": jsonTypes.verbose,
74
- "Authorization": `Bearer ${authToken}`,
75
- "content-type": jsonTypes.verbose,
76
- "x-anchormailbox": _spPageContextInfo.userEmail.toLowerCase(),
77
- "x-findmeetinglocations-appname": "sharepoint",
78
- "x-findmeetinglocations-appscenario": "locationfield",
79
- }
80
- });
81
-
82
- if (!isNullOrUndefined(result) && !isNullOrEmptyArray(result.MeetingLocations)) {
83
- let value = result.MeetingLocations.map((loc) => {
84
- return loc.MeetingLocation;
85
- });
86
- return value;
87
- }
88
-
89
- return null;
90
- }
91
-
92
- /**
93
- * Get meeting locations using outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations
94
- * @param query The term to search for
95
- * @returns An array of meeting locations (https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0) sorted by relevance score
96
- */
97
- export async function FindMeetingLocations(query: string) {
98
- let results = await _findMeetingLocations({ query: query, bingUri: null });
99
- return !isNullOrEmptyArray(results) ? results : null;
100
- }
101
-
102
- /**
103
- * Resolve meeting locations using outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations
104
- * @param bingUri The LocationUri for the meeting location
105
- * @returns A single meeting location
106
- */
107
- export async function ResolveLocationFromBingUri(bingUri: string) {
108
- let results = await _findMeetingLocations({ query: null, bingUri: bingUri });
109
- return !isNullOrEmptyArray(results) ? results[0] : null;
110
- }
111
-
112
- //example response
113
- //{
114
- // "MeetingLocations":
115
- // [{
116
- // "MeetingLocation":
117
- // {
118
- // "EntityType": "LocalBusiness",
119
- // "LocationSource": "Bing",
120
- // "LocationUri":
121
- // "https://www.bingapis.com/api/v6/localbusinesses/YN1226x25906078?setLang=en-CA",
122
- // "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x25906078?setLang=en-CA",
123
- // "IsPreviouslyUsed": false, "DisplayName": "The Home Depot",
124
- // "Address": {
125
- // "Street": "99 Cross Ave",
126
- // "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6J 2W7"
127
- // }, "Coordinates": { "Latitude": 43.4548, "Longitude": -79.6886 }
128
- // },
129
- // "LocationType": "LocalBusiness",
130
- // "RelevanceScore": -20.0,
131
- // "RelevanceHint": "NonHistory"
132
- // },
133
- // {
134
- // "MeetingLocation":
135
- // {
136
- // "EntityType": "LocalBusiness", "LocationSource": "Bing",
137
- // "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x262267234?setLang=en-CA",
138
- // "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x262267234?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "3300 South Service Rd W", "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6L 0B1" }, "Coordinates": { "Latitude": 43.3994, "Longitude": -79.7496 }
139
- // }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory"
140
- // }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1227x25906192?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1227x25906192?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "3050 Davidson Crt", "City": "Burlington", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L7M 4M9" }, "Coordinates": { "Latitude": 43.3557, "Longitude": -79.8067 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x15474422097876230312?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x15474422097876230312?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "2555 Bristol Circle", "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6H 5W9" }, "Coordinates": { "Latitude": 43.518, "Longitude": -79.6847 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1228x262604067?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1228x262604067?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "350 Centennial Pky N", "City": "Hamilton", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L8E 2X4" }, "Coordinates": { "Latitude": 43.2402, "Longitude": -79.7575 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }],
141
- // "EmptyLocationsHint": ""
1
+ import { waitFor } from "../../helpers/browser";
2
+ import { isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isTypeofFullNameUndefined } from "../../helpers/typecheckers";
3
+ import { SPFxAuthTokenType } from "../../types/auth";
4
+ import { IMeetingLocation, IMeetingLocationEntityType } from "../../types/location.types";
5
+ import { jsonTypes } from "../../types/rest.types";
6
+ import { GetSPFxClientAuthToken } from "../auth/common";
7
+ import { GetJson, shortLocalCache } from "../rest";
8
+
9
+ interface IMeetingLocationsQuery {
10
+ QueryConstraint: {
11
+ Query: string;
12
+ Id?: string;
13
+ ResolveAvailability?: boolean;
14
+ };
15
+ LocationProvider: 32 | 8;
16
+ BingMarket?: string;
17
+ }
18
+
19
+ interface IMeetingLocationResult {
20
+ LocationType: IMeetingLocationEntityType
21
+ RelevanceHint: string;
22
+ RelevanceScore: number;
23
+ MeetingLocation: IMeetingLocation;
24
+ }
25
+
26
+ interface IMeetingLocationsResponse {
27
+ MeetingLocations: IMeetingLocationResult[],
28
+ EmptyLocationsHint: string;
29
+ }
30
+
31
+ async function _findMeetingLocations(options: { bingUri: string; query: string }) {
32
+ if (isNullOrUndefined(options) || (isNullOrEmptyString(options.bingUri) && isNullOrEmptyString(options.query))) {
33
+ return null;
34
+ }
35
+
36
+ let contextReady = await waitFor(() => {
37
+ return !isTypeofFullNameUndefined("_spPageContextInfo");
38
+ });
39
+
40
+ if (!contextReady) {
41
+ return null;
42
+ }
43
+
44
+ let authToken = await GetSPFxClientAuthToken(_spPageContextInfo.webServerRelativeUrl, SPFxAuthTokenType.Outlook);
45
+
46
+ if (isNullOrEmptyString(authToken)) {
47
+ return null;
48
+ }
49
+
50
+ const { query, bingUri } = options;
51
+
52
+ let useBingUri = !isNullOrEmptyString(bingUri);
53
+
54
+ let queryData: IMeetingLocationsQuery = {
55
+ QueryConstraint: {
56
+ Query: useBingUri === true ? "" : query,
57
+ Id: useBingUri === true ? bingUri : undefined,
58
+ ResolveAvailability: useBingUri === true ? false : undefined
59
+ },
60
+ LocationProvider: useBingUri ? 8 : 32,
61
+ BingMarket: _spPageContextInfo.currentCultureName
62
+ };
63
+
64
+ let url = "https://outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations";
65
+ let result = await GetJson<IMeetingLocationsResponse>(
66
+ url,
67
+ JSON.stringify(queryData),
68
+ {
69
+ ...shortLocalCache,
70
+ postCacheKey: `${queryData.BingMarket}|${queryData.LocationProvider}|${useBingUri ? queryData.QueryConstraint.Id : queryData.QueryConstraint.Query}`,
71
+ includeDigestInPost: false,
72
+ headers: {
73
+ "Accept": jsonTypes.verbose,
74
+ "Authorization": `Bearer ${authToken}`,
75
+ "content-type": jsonTypes.verbose,
76
+ "x-anchormailbox": _spPageContextInfo.userEmail.toLowerCase(),
77
+ "x-findmeetinglocations-appname": "sharepoint",
78
+ "x-findmeetinglocations-appscenario": "locationfield",
79
+ }
80
+ });
81
+
82
+ if (!isNullOrUndefined(result) && !isNullOrEmptyArray(result.MeetingLocations)) {
83
+ let value = result.MeetingLocations.map((loc) => {
84
+ return loc.MeetingLocation;
85
+ });
86
+ return value;
87
+ }
88
+
89
+ return null;
90
+ }
91
+
92
+ /**
93
+ * Get meeting locations using outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations
94
+ * @param query The term to search for
95
+ * @returns An array of meeting locations (https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0) sorted by relevance score
96
+ */
97
+ export async function FindMeetingLocations(query: string) {
98
+ let results = await _findMeetingLocations({ query: query, bingUri: null });
99
+ return !isNullOrEmptyArray(results) ? results : null;
100
+ }
101
+
102
+ /**
103
+ * Resolve meeting locations using outlook.office365.com/SchedulingB2/api/v1.0/me/findmeetinglocations
104
+ * @param bingUri The LocationUri for the meeting location
105
+ * @returns A single meeting location
106
+ */
107
+ export async function ResolveLocationFromBingUri(bingUri: string) {
108
+ let results = await _findMeetingLocations({ query: null, bingUri: bingUri });
109
+ return !isNullOrEmptyArray(results) ? results[0] : null;
110
+ }
111
+
112
+ //example response
113
+ //{
114
+ // "MeetingLocations":
115
+ // [{
116
+ // "MeetingLocation":
117
+ // {
118
+ // "EntityType": "LocalBusiness",
119
+ // "LocationSource": "Bing",
120
+ // "LocationUri":
121
+ // "https://www.bingapis.com/api/v6/localbusinesses/YN1226x25906078?setLang=en-CA",
122
+ // "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x25906078?setLang=en-CA",
123
+ // "IsPreviouslyUsed": false, "DisplayName": "The Home Depot",
124
+ // "Address": {
125
+ // "Street": "99 Cross Ave",
126
+ // "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6J 2W7"
127
+ // }, "Coordinates": { "Latitude": 43.4548, "Longitude": -79.6886 }
128
+ // },
129
+ // "LocationType": "LocalBusiness",
130
+ // "RelevanceScore": -20.0,
131
+ // "RelevanceHint": "NonHistory"
132
+ // },
133
+ // {
134
+ // "MeetingLocation":
135
+ // {
136
+ // "EntityType": "LocalBusiness", "LocationSource": "Bing",
137
+ // "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x262267234?setLang=en-CA",
138
+ // "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x262267234?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "3300 South Service Rd W", "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6L 0B1" }, "Coordinates": { "Latitude": 43.3994, "Longitude": -79.7496 }
139
+ // }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory"
140
+ // }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1227x25906192?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1227x25906192?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "3050 Davidson Crt", "City": "Burlington", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L7M 4M9" }, "Coordinates": { "Latitude": 43.3557, "Longitude": -79.8067 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x15474422097876230312?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1226x15474422097876230312?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "2555 Bristol Circle", "City": "Oakville", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L6H 5W9" }, "Coordinates": { "Latitude": 43.518, "Longitude": -79.6847 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }, { "MeetingLocation": { "EntityType": "LocalBusiness", "LocationSource": "Bing", "LocationUri": "https://www.bingapis.com/api/v6/localbusinesses/YN1228x262604067?setLang=en-CA", "UniqueId": "https://www.bingapis.com/api/v6/localbusinesses/YN1228x262604067?setLang=en-CA", "IsPreviouslyUsed": false, "DisplayName": "The Home Depot", "Address": { "Street": "350 Centennial Pky N", "City": "Hamilton", "State": "ON", "CountryOrRegion": "Canada", "PostalCode": "L8E 2X4" }, "Coordinates": { "Latitude": 43.2402, "Longitude": -79.7575 } }, "LocationType": "LocalBusiness", "RelevanceScore": -20.0, "RelevanceHint": "NonHistory" }],
141
+ // "EmptyLocationsHint": ""
142
142
  // }
@@ -1,87 +1,87 @@
1
- import { isNullOrEmptyString, isNullOrUndefined } from "../../helpers/typecheckers";
2
- import { INavLinkInfo } from "../../types/sharepoint.types";
3
- import { ConsoleLogger } from "../consolelogger";
4
- import { GetJson } from "../rest";
5
- import { GetRestBaseUrl, GetSiteUrl } from "./common";
6
-
7
- const logger = ConsoleLogger.get("SharePoint.Rest.Navigation-Links");
8
-
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
- export async function GetNavigationLinks(siteUrl?: string): Promise<INavLinkInfo[]> {
15
- siteUrl = GetSiteUrl(siteUrl);
16
- const topNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/topnavigationbar`;
17
- const sideNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/quicklaunch`;
18
-
19
- try {
20
- const topNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(topNavUrl);
21
- const sideNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(sideNavUrl);
22
-
23
- const topNavLinks: INavLinkInfo[] = topNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "topnavigationbar" }));
24
- const sideNavLinks: INavLinkInfo[] = sideNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "quicklaunch" }));
25
-
26
- return [...topNavLinks, ...sideNavLinks];
27
- } catch (error) {
28
- logger.error(`Error fetching navigation links: ${error.message}`);
29
- }
30
- return [];
31
- }
32
-
33
- /**
34
- * Add a navigation link to the specified location (top navigation or side navigation)
35
- * @param title The title of the navigation link
36
- * @param url The url of the navigation link
37
- * @param location The location where the link will be added ('topnavigationbar' or 'quicklaunch'). Default is 'quicklaunch'.
38
- * @Logs If the location is invalid or if adding the link fails
39
- */
40
- export async function AddNavigationLink(title: string, url: string, location: 'topnavigationbar' | 'quicklaunch' = 'quicklaunch'): Promise<INavLinkInfo> {
41
- try {
42
- let siteUrl = GetSiteUrl();
43
- let navigationUrl = "";
44
- navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/${location}`;
45
- const response = await GetJson<{ d: INavLinkInfo }>(navigationUrl, JSON.stringify({
46
- '__metadata': { 'type': 'SP.NavigationNode' },
47
- 'Title': title,
48
- 'Url': url
49
- }), {
50
- spWebUrl: siteUrl,
51
- });
52
-
53
-
54
- if (!isNullOrUndefined(response) && !isNullOrUndefined(response.d)) {
55
- return response.d;
56
- }
57
- } catch (error) {
58
- logger.error('Error adding link');
59
- }
60
- }
61
-
62
- /**
63
- * Delete navigation links by title and URL
64
- * @param navLinks An array of navigation links to be deleted
65
- * @Logs If the location is invalid or if deleting the links fails
66
- */
67
- export async function DeleteNavigationLinks(navLinks: INavLinkInfo[]): Promise<void> {
68
- try {
69
- const siteUrl = GetSiteUrl();
70
- for (const navLink of navLinks) {
71
- const navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/Navigation/GetNodeById(${navLink.Id})`;
72
- // Use the same convention to make the DELETE request
73
- const response = await GetJson<any>(navigationUrl, null, {
74
- method: 'POST',
75
- spWebUrl: siteUrl,
76
- xHttpMethod: 'DELETE'
77
- });
78
-
79
- if (!isNullOrEmptyString(response) && !response.ok) {
80
- logger.error('Failed to delete link');
81
- }
82
- }
83
- logger.info('Navigation links deleted successfully');
84
- } catch (error) {
85
- logger.error('Error deleting links');
86
- }
1
+ import { isNullOrEmptyString, isNullOrUndefined } from "../../helpers/typecheckers";
2
+ import { INavLinkInfo } from "../../types/sharepoint.types";
3
+ import { ConsoleLogger } from "../consolelogger";
4
+ import { GetJson } from "../rest";
5
+ import { GetRestBaseUrl, GetSiteUrl } from "./common";
6
+
7
+ const logger = ConsoleLogger.get("SharePoint.Rest.Navigation-Links");
8
+
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
+ export async function GetNavigationLinks(siteUrl?: string): Promise<INavLinkInfo[]> {
15
+ siteUrl = GetSiteUrl(siteUrl);
16
+ const topNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/topnavigationbar`;
17
+ const sideNavUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/quicklaunch`;
18
+
19
+ try {
20
+ const topNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(topNavUrl);
21
+ const sideNavResponse = await GetJson<{ d: { results: INavLinkInfo[] } }>(sideNavUrl);
22
+
23
+ const topNavLinks: INavLinkInfo[] = topNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "topnavigationbar" }));
24
+ const sideNavLinks: INavLinkInfo[] = sideNavResponse.d.results.map((link: INavLinkInfo) => ({ ...link, Location: "quicklaunch" }));
25
+
26
+ return [...topNavLinks, ...sideNavLinks];
27
+ } catch (error) {
28
+ logger.error(`Error fetching navigation links: ${error.message}`);
29
+ }
30
+ return [];
31
+ }
32
+
33
+ /**
34
+ * Add a navigation link to the specified location (top navigation or side navigation)
35
+ * @param title The title of the navigation link
36
+ * @param url The url of the navigation link
37
+ * @param location The location where the link will be added ('topnavigationbar' or 'quicklaunch'). Default is 'quicklaunch'.
38
+ * @Logs If the location is invalid or if adding the link fails
39
+ */
40
+ export async function AddNavigationLink(title: string, url: string, location: 'topnavigationbar' | 'quicklaunch' = 'quicklaunch'): Promise<INavLinkInfo> {
41
+ try {
42
+ let siteUrl = GetSiteUrl();
43
+ let navigationUrl = "";
44
+ navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/navigation/${location}`;
45
+ const response = await GetJson<{ d: INavLinkInfo }>(navigationUrl, JSON.stringify({
46
+ '__metadata': { 'type': 'SP.NavigationNode' },
47
+ 'Title': title,
48
+ 'Url': url
49
+ }), {
50
+ spWebUrl: siteUrl,
51
+ });
52
+
53
+
54
+ if (!isNullOrUndefined(response) && !isNullOrUndefined(response.d)) {
55
+ return response.d;
56
+ }
57
+ } catch (error) {
58
+ logger.error('Error adding link');
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Delete navigation links by title and URL
64
+ * @param navLinks An array of navigation links to be deleted
65
+ * @Logs If the location is invalid or if deleting the links fails
66
+ */
67
+ export async function DeleteNavigationLinks(navLinks: INavLinkInfo[]): Promise<void> {
68
+ try {
69
+ const siteUrl = GetSiteUrl();
70
+ for (const navLink of navLinks) {
71
+ const navigationUrl = `${GetRestBaseUrl(siteUrl)}/web/Navigation/GetNodeById(${navLink.Id})`;
72
+ // Use the same convention to make the DELETE request
73
+ const response = await GetJson<any>(navigationUrl, null, {
74
+ method: 'POST',
75
+ spWebUrl: siteUrl,
76
+ xHttpMethod: 'DELETE'
77
+ });
78
+
79
+ if (!isNullOrEmptyString(response) && !response.ok) {
80
+ logger.error('Failed to delete link');
81
+ }
82
+ }
83
+ logger.info('Navigation links deleted successfully');
84
+ } catch (error) {
85
+ logger.error('Error deleting links');
86
+ }
87
87
  }