@kwiz/common 1.0.129 → 1.0.133

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 (111) hide show
  1. package/LICENSE +21 -21
  2. package/lib/cjs/config.js +2 -0
  3. package/lib/cjs/config.js.map +1 -1
  4. package/lib/cjs/types/libs/msal.types.js +26 -26
  5. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  6. package/lib/esm/config.js +2 -0
  7. package/lib/esm/config.js.map +1 -1
  8. package/lib/esm/types/libs/msal.types.js +26 -26
  9. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  10. package/lib/types/config.d.ts +2 -0
  11. package/package.json +81 -81
  12. package/readme.md +17 -17
  13. package/.github/workflows/npm-publish.yml +0 -24
  14. package/.madgerc +0 -3
  15. package/fix-folder-imports.js +0 -27
  16. package/src/_dependencies.ts +0 -13
  17. package/src/config.ts +0 -17
  18. package/src/exports-index.ts +0 -4
  19. package/src/helpers/Guid.ts +0 -182
  20. package/src/helpers/base64.ts +0 -174
  21. package/src/helpers/browser.test.js +0 -13
  22. package/src/helpers/browser.ts +0 -1505
  23. package/src/helpers/browserinfo.ts +0 -293
  24. package/src/helpers/collections.base.test.js +0 -26
  25. package/src/helpers/collections.base.ts +0 -438
  26. package/src/helpers/collections.ts +0 -108
  27. package/src/helpers/color.ts +0 -55
  28. package/src/helpers/cookies.ts +0 -60
  29. package/src/helpers/date.test.js +0 -120
  30. package/src/helpers/date.ts +0 -189
  31. package/src/helpers/debug.ts +0 -187
  32. package/src/helpers/diagrams.ts +0 -44
  33. package/src/helpers/emails.ts +0 -7
  34. package/src/helpers/eval.ts +0 -5
  35. package/src/helpers/exports-index.ts +0 -30
  36. package/src/helpers/file.test.js +0 -51
  37. package/src/helpers/file.ts +0 -64
  38. package/src/helpers/flatted.ts +0 -150
  39. package/src/helpers/functions.ts +0 -17
  40. package/src/helpers/graph/calendar.types.ts +0 -11
  41. package/src/helpers/graph/exports-index.ts +0 -1
  42. package/src/helpers/http.ts +0 -70
  43. package/src/helpers/images.ts +0 -23
  44. package/src/helpers/json.ts +0 -45
  45. package/src/helpers/md5.ts +0 -190
  46. package/src/helpers/objects.test.js +0 -34
  47. package/src/helpers/objects.ts +0 -275
  48. package/src/helpers/promises.test.js +0 -38
  49. package/src/helpers/promises.ts +0 -166
  50. package/src/helpers/random.ts +0 -27
  51. package/src/helpers/scheduler/exports-index.ts +0 -1
  52. package/src/helpers/scheduler/scheduler.test.js +0 -104
  53. package/src/helpers/scheduler/scheduler.ts +0 -132
  54. package/src/helpers/sharepoint.ts +0 -797
  55. package/src/helpers/strings.test.js +0 -123
  56. package/src/helpers/strings.ts +0 -338
  57. package/src/helpers/typecheckers.test.js +0 -35
  58. package/src/helpers/typecheckers.ts +0 -267
  59. package/src/helpers/url.test.js +0 -44
  60. package/src/helpers/url.ts +0 -208
  61. package/src/helpers/urlhelper.ts +0 -112
  62. package/src/index.ts +0 -6
  63. package/src/types/auth.ts +0 -63
  64. package/src/types/common.types.ts +0 -16
  65. package/src/types/exports-index.ts +0 -15
  66. package/src/types/flatted.types.ts +0 -60
  67. package/src/types/globals.types.ts +0 -7
  68. package/src/types/graph/calendar.types.ts +0 -81
  69. package/src/types/graph/exports-index.ts +0 -1
  70. package/src/types/knownscript.types.ts +0 -19
  71. package/src/types/libs/datajs.types.ts +0 -29
  72. package/src/types/libs/exports-index.ts +0 -3
  73. package/src/types/libs/ics.types.ts +0 -31
  74. package/src/types/libs/msal.types.ts +0 -58
  75. package/src/types/locales.ts +0 -126
  76. package/src/types/localstoragecache.types.ts +0 -9
  77. package/src/types/location.types.ts +0 -28
  78. package/src/types/moment.ts +0 -12
  79. package/src/types/regex.types.ts +0 -17
  80. package/src/types/rest.types.ts +0 -96
  81. package/src/types/sharepoint.types.ts +0 -1467
  82. package/src/types/sharepoint.utils.types.ts +0 -307
  83. package/src/utils/auth/common.ts +0 -119
  84. package/src/utils/auth/discovery.test.js +0 -13
  85. package/src/utils/auth/discovery.ts +0 -132
  86. package/src/utils/auth/exports-index.ts +0 -2
  87. package/src/utils/base64.ts +0 -28
  88. package/src/utils/consolelogger.ts +0 -334
  89. package/src/utils/date.ts +0 -173
  90. package/src/utils/emails.ts +0 -25
  91. package/src/utils/exports-index.ts +0 -11
  92. package/src/utils/knownscript.ts +0 -287
  93. package/src/utils/localstoragecache.ts +0 -447
  94. package/src/utils/rest.ts +0 -502
  95. package/src/utils/script.ts +0 -171
  96. package/src/utils/sharepoint.rest/common.ts +0 -160
  97. package/src/utils/sharepoint.rest/date.ts +0 -63
  98. package/src/utils/sharepoint.rest/exports-index.ts +0 -11
  99. package/src/utils/sharepoint.rest/file.folder.ts +0 -685
  100. package/src/utils/sharepoint.rest/item.ts +0 -547
  101. package/src/utils/sharepoint.rest/list.ts +0 -1572
  102. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -775
  103. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -275
  104. package/src/utils/sharepoint.rest/listutils/common.ts +0 -207
  105. package/src/utils/sharepoint.rest/listutils/exports-index.ts +0 -3
  106. package/src/utils/sharepoint.rest/location.ts +0 -142
  107. package/src/utils/sharepoint.rest/navigation-links.ts +0 -87
  108. package/src/utils/sharepoint.rest/user-search.ts +0 -253
  109. package/src/utils/sharepoint.rest/user.ts +0 -559
  110. package/src/utils/sharepoint.rest/web.ts +0 -1385
  111. package/src/utils/sod.ts +0 -195
@@ -1,307 +0,0 @@
1
- /** types for KWIZ sharepoint API */
2
- import { IDictionary } from "./common.types";
3
- import { AttachmentFilesRESTValue, BaseTypes, FileSystemObjectTypes, IFieldInfoEX, ISPEventReceiver, ListTemplateTypes, PrincipalType, RoleType } from "./sharepoint.types";
4
-
5
- export interface ISiteInfo { Id: string; ServerRelativeUrl: string; }
6
- export interface IRootWebInfo { Id: string; ServerRelativeUrl: string; }
7
-
8
- export interface ISPRestError {
9
- code: string;
10
- message: string;
11
- }
12
-
13
- export interface IUserInfo {
14
- Id: number;
15
- LoginName: string;
16
- UserPrincipalName: string;
17
- Title: string;
18
- IsSiteAdmin: boolean;
19
- Email: string;
20
- Groups?: IUserGroupInfo[];
21
- PrincipalType: PrincipalType;
22
- }
23
- export interface IUserGroupInfo {
24
- Id: number;
25
- LoginName: string;
26
- Title: string;
27
- Description: string;
28
- }
29
-
30
- export interface IGroupInfo {
31
- Id: number;
32
- Title: string;
33
- Description: string;
34
- CanCurrentUserViewMembership: boolean;
35
- OnlyAllowMembersViewMembership: boolean;
36
- LoginName: string;
37
- Users?: IUserInfo[];
38
- PrincipalType: PrincipalType.SharePointGroup;
39
- IsHiddenInUI?: boolean;
40
- OwnerTitle?: string;
41
- }
42
-
43
- // eslint-disable-next-line no-shadow
44
- export enum ListExperienceOptions {
45
- Default = 0,
46
- Modern = 1,
47
- Classic = 2
48
- }
49
-
50
- export interface iList {
51
- Title: string;
52
- Description: string;
53
- EnableAttachments: boolean;
54
- EnableModeration: boolean;
55
- BaseTemplate: ListTemplateTypes;
56
- BaseType: BaseTypes;
57
- Id: string;
58
- Hidden: boolean;
59
- IsApplicationList: boolean;
60
- IsPrivate: boolean;
61
- IsCatalog: boolean;
62
- ImageUrl: string;
63
- ItemCount: number;
64
- ParentWebUrl: string;
65
- EntityTypeName: string;
66
- DefaultViewUrl: string;
67
- ParentWeb: { Id: string; Title: string; };
68
- Views?: iListView[];
69
- ContentTypes?: iContentType[];
70
- EffectiveBasePermissions: { High: number; Low: number; },
71
- RootFolder?: {
72
- ServerRelativeUrl: string;
73
- Name: string;
74
- };
75
- EventReceivers?: ISPEventReceiver[];
76
- ListExperienceOptions?: ListExperienceOptions;
77
- }
78
-
79
- export enum DraftVisibilityType {
80
- Reader = 0,
81
- /** default */
82
- Author = 1,
83
- /** approvers, and the person who submitted the draft */
84
- Approver = 2
85
- }
86
-
87
- export interface iListVersionSettings {
88
- /** saving creates a draft */
89
- EnableMinorVersions: boolean;
90
- /** @deprecated versioning is enabled. (this is now always on in M365 libraries) */
91
- EnableVersioning: boolean;
92
- DraftVersionVisibility: DraftVisibilityType;
93
- MajorWithMinorVersionsLimit: number;
94
- MajorVersionLimit: number;
95
- EnableModeration: boolean;
96
- }
97
-
98
- export interface iListView {
99
- Title: string;
100
- Id: string;
101
- ServerRelativeUrl: string;
102
- RowLimit: number;
103
- Paged: boolean;
104
- ViewQuery: string;
105
- ListViewXml: string;
106
- PersonalView: boolean;
107
- MobileView: boolean;
108
- MobileDefaultView: boolean;
109
- Hidden: boolean;
110
- DefaultView: boolean;
111
- ReadOnlyView: boolean;
112
- ViewFields?: string[];
113
- }
114
-
115
- export interface IListWorkflowAssociation {
116
- AllowManual: boolean;
117
- BaseId: string;//guid
118
- Created: string;
119
- Description: string;
120
- Enabled: boolean;
121
- HistoryListTitle: string;
122
- Id: string;//guid
123
- InstantiationUrl?: string;
124
- InternalName: string;
125
- IsDeclarative: boolean;
126
- ListId: string;//guid
127
- Modified: string;
128
- Name: string;
129
- RunningInstances: number;
130
- TaskListTitle: string;
131
- WebId: string;//guid
132
- }
133
-
134
- export interface iContentType {
135
- Name: string;
136
- Description: string;
137
- StringId: string;
138
- Group: string;
139
- Hidden: boolean;
140
- ReadOnly: boolean;
141
- NewFormUrl: string;
142
- DisplayFormUrl: string;
143
- EditFormUrl: string;
144
- Fields?: IFieldInfoEX[];
145
- Sealed: boolean;
146
- MobileNewFormUrl: string;
147
- MobileDisplayFormUrl: string;
148
- MobileEditFormUrl: string;
149
- NewFormTemplateName: string;
150
- DisplayFormTemplateName: string;
151
- EditFormTemplateName: string;
152
- }
153
-
154
- // eslint-disable-next-line no-shadow
155
- export enum WebTypes {
156
- Team = 0,
157
- Group = 1,
158
- App = 2,
159
- Other = 3
160
- }
161
- export interface IWebBasicInfo {
162
- Title: string;
163
- ServerRelativeUrl: string;
164
- WebId: string;
165
- /**STS, APP, WIKI, MPS, APPCATALOG, DEV, PWA, PWS, SPS, GROUP or other... */
166
- WebTemplate: "STS" | "APP" | "WIKI" | "MPS" | "APPCATALOG" | "DEV" | "PWA" | "PWS" | "SPS" | "GROUP" | string;
167
- WebType: WebTypes;
168
- Description?: string;
169
- SiteLogoUrl?: string;
170
- }
171
-
172
- export interface IRestRoleDefinition {
173
- BasePermissions: { High: number; Low: number; };
174
- Description: string;
175
- Hidden: boolean;
176
- Id: number;
177
- Name: string;
178
- Order: number;
179
- RoleTypeKind: RoleType;
180
- }
181
-
182
- export interface IAppTile {
183
- Title: string;
184
- ProductId: string;
185
- }
186
-
187
- export interface IFileInfo {
188
- Exists: boolean;
189
- Name: string;
190
- ServerRelativeUrl: string;
191
- TimeCreated: Date;
192
- TimeLastModified: Date;
193
- Title: string;
194
- Level: FileLevel;
195
- }
196
-
197
- export interface IFileInfoWithModerationStatus extends IFileInfo {
198
- ListItemAllFields?: {
199
- OData__ModerationStatus?: ModerationStatus
200
- }
201
- }
202
-
203
- export interface ITimeZone {
204
- Description: string;
205
- Id: number;
206
- Information: { Bias: number; DaylightBias: number; StandardBias: number; };
207
- }
208
-
209
- // eslint-disable-next-line no-shadow
210
- export enum GeListItemsFoldersBehaviour { AllItemsNoFolders, ItemsAndFoldersFlat, ItemsInsideFolders }
211
-
212
- export interface IRestItem {
213
- Id: number;
214
- FileRef: string;
215
- FileDirRef: string;
216
- FileLeafRef: string;
217
- /** file type (lower case) or 'folder' or 'listitem' */
218
- FileType: 'folder' | 'listitem' | string;
219
- /** Folder=1, list item=0 */
220
- FileSystemObjectType: FileSystemObjectTypes;
221
- [InternalName: string]: any;
222
- FieldValuesAsText?: IDictionary<string>;
223
- FieldValuesForEdit?: IDictionary<any>;
224
- AttachmentFiles?: AttachmentFilesRESTValue;
225
-
226
- /** File name (no extension) for files or folders, Title for list items or 'Item #ID' for items with an empty title */
227
- __DisplayTitle: string;
228
- /** For a folder, this will have items inside the folder */
229
- __Items?: IRestItem[];
230
- /** For an item inside a folder, this will be the parent folder */
231
- __ParentFolder?: IRestItem;
232
- }
233
-
234
- export interface IRestItemExpandedLookupValue {
235
- Id: number;
236
- Title: string;
237
- }
238
-
239
- export type UserEntityValueType = {
240
- principalType: PrincipalType.User | PrincipalType.SecurityGroup | PrincipalType.SharePointGroup;
241
- spId: number;
242
- loginOrPrincipalName?: string;
243
- /** not saved in settings. pre-loaded when loading settings. */
244
- title?: string;
245
- /** not saved in settings. pre-loaded when loading settings. */
246
- email?: string;
247
- };
248
-
249
- export interface IWebRegionalSettings {
250
- AdjustHijriDays: number;
251
- AlternateCalendarType: number;
252
- AM: string;
253
- CalendarType: number;
254
- Collation: number;
255
- CollationLCID: number;
256
- DateFormat: number;
257
- DateSeparator: string;
258
- DecimalSeparator: string;
259
- DigitGrouping: string;
260
- FirstDayOfWeek: number;
261
- FirstWeekOfYear: number;
262
- IsEastAsia: boolean;
263
- IsRightToLeft: boolean;
264
- IsUIRightToLeft: boolean;
265
- ListSeparator: string;
266
- LocaleId: number;
267
- NegativeSign: string;
268
- NegNumberMode: number;
269
- PM: string;
270
- PositiveSign: string;
271
- ShowWeeks: boolean;
272
- ThousandSeparator: string;
273
- Time24: boolean;
274
- TimeMarkerPosition: number;
275
- TimeSeparator: string;
276
- WorkDayEndHour: number;
277
- WorkDays: number;
278
- WorkDayStartHour: number;
279
- }
280
-
281
- /**
282
- * Specifies the moderation status for a file/item (https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-wssfo3/4342322d-6fab-4dc5-8ccd-b808a5e25acf)
283
- */
284
- export enum ModerationStatus {
285
- /** The list item is approved. */
286
- Approved,
287
- /** The list item has been denied approval. */
288
- Rejected,
289
- /** The list item is pending approval. */
290
- Pending,
291
- /** The list item is in the draft or checked out state. */
292
- Draft,
293
- /** The list item is scheduled for automatic approval at a future date. */
294
- Scheduled
295
- }
296
-
297
- /**
298
- * Specifies the publishing level for a file (https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj246272(v=office.15))
299
- */
300
- export enum FileLevel {
301
- /** Enumeration whose values specify whether the file is a published version. */
302
- Published = 1,
303
- /** Enumeration whose values specify whether the file is a draft.. */
304
- Draft = 2,
305
- /** Enumeration whose values specify whether the file is checked out to the current user. */
306
- Checkout = 255
307
- }
@@ -1,119 +0,0 @@
1
- import { getCacheItem, IRestOptions, setCacheItem } from "../../exports-index";
2
- import { isNullOrEmptyString, isNullOrUndefined, isNumber } from "../../helpers/typecheckers";
3
- import { SPFxAuthToken, SPFxAuthTokenType } from "../../types/auth";
4
- import { GetJson, GetJsonSync } from "../rest";
5
- import { GetRestBaseUrl } from "../sharepoint.rest/common";
6
-
7
- export function GetTokenAudiencePrefix(appId: string) {
8
- return `api://${appId}`;
9
- }
10
- export function GetDefaultScope(appId: string) {
11
- return `${GetTokenAudiencePrefix(appId)}/access_as_user`;
12
- }
13
- export function GetMSALSiteScope(hostName: string) {
14
- return `https://${hostName}`;
15
- }
16
-
17
- function _getGetSPFxClientAuthTokenParams(siteUrl: string, spfxTokenType: SPFxAuthTokenType = SPFxAuthTokenType.Graph) {
18
- let acquireURL = `${GetRestBaseUrl(siteUrl)}/SP.OAuth.Token/Acquire`;
19
- //todo: add all the resource end points (ie. OneNote, Yammer, Stream)
20
- let resource = "";
21
- let isSPOToken = false;
22
- switch (spfxTokenType) {
23
- case SPFxAuthTokenType.Outlook:
24
- resource = "https://outlook.office365.com/search";
25
- break;
26
- case SPFxAuthTokenType.SharePoint:
27
- case SPFxAuthTokenType.MySite:
28
- isSPOToken = true;
29
- resource = new URL(acquireURL).origin;
30
- if (spfxTokenType === SPFxAuthTokenType.MySite) {
31
- let split = resource.split(".");
32
- split[0] += "-my";
33
- resource = split.join(".");
34
- }
35
- break;
36
- default:
37
- resource = "https://graph.microsoft.com";
38
- }
39
-
40
- let data = {
41
- resource: resource,
42
- tokenType: isSPOToken ? "SPO" : undefined
43
- };
44
-
45
- let params: {
46
- url: string,
47
- body: string,
48
- options: IRestOptions
49
- } = {
50
- url: acquireURL,
51
- body: JSON.stringify(data),
52
- options: {
53
- allowCache: false,
54
- // ...shortLocalCache,
55
- // postCacheKey: `${spfxTokenType}_${_spPageContextInfo.webId}`,
56
- includeDigestInPost: true,
57
- headers: {
58
- "Accept": "application/json;odata.metadata=minimal",
59
- "content-type": "application/json; charset=UTF-8",
60
- "odata-version": "4.0",
61
- }
62
- }
63
- };
64
-
65
- return params;
66
- }
67
-
68
- function _parseAndCacheGetSPFxClientAuthTokenResult(result: SPFxAuthToken, spfxTokenType: SPFxAuthTokenType = SPFxAuthTokenType.Graph) {
69
- if (!isNullOrUndefined(result) && !isNullOrEmptyString(result.access_token)) {
70
- let expiration = isNumber(result.expires_on) ?
71
- new Date(result.expires_on * 1000) :
72
- {
73
- minutes: 15
74
- };
75
-
76
- setCacheItem(`access_token_${spfxTokenType}_${_spPageContextInfo.webId}`, result.access_token, expiration);
77
-
78
- return result.access_token;
79
- }
80
- return null;
81
- }
82
-
83
- function _getSPFxClientAuthTokenFromCache(spfxTokenType: SPFxAuthTokenType = SPFxAuthTokenType.Graph) {
84
- let cachedToken = getCacheItem<string>(`access_token_${spfxTokenType}_${_spPageContextInfo.webId}`);
85
- if (!isNullOrEmptyString(cachedToken)) {
86
- return cachedToken;
87
- }
88
- return null;
89
- }
90
-
91
- /** Acquire an authorization token for a Outlook, Graph, or SharePoint the same way SPFx clients do */
92
- export async function GetSPFxClientAuthToken(siteUrl: string, spfxTokenType: SPFxAuthTokenType = SPFxAuthTokenType.Graph) {
93
- try {
94
- let cachedToken = _getSPFxClientAuthTokenFromCache(spfxTokenType);
95
- if (!isNullOrEmptyString(cachedToken)) {
96
- return cachedToken;
97
- }
98
- let { url, body, options } = _getGetSPFxClientAuthTokenParams(siteUrl, spfxTokenType);
99
- let result = await GetJson<SPFxAuthToken>(url, body, options);
100
- return _parseAndCacheGetSPFxClientAuthTokenResult(result, spfxTokenType);
101
- } catch {
102
- }
103
- return null;
104
- }
105
-
106
- /** Acquire an authorization token for a Outlook, Graph, or SharePoint the same way SPFx clients do */
107
- export function GetSPFxClientAuthTokenSync(siteUrl: string, spfxTokenType: SPFxAuthTokenType = SPFxAuthTokenType.Graph) {
108
- try {
109
- let cachedToken = _getSPFxClientAuthTokenFromCache(spfxTokenType);
110
- if (!isNullOrEmptyString(cachedToken)) {
111
- return cachedToken;
112
- }
113
- let { url, body, options } = _getGetSPFxClientAuthTokenParams(siteUrl, spfxTokenType);
114
- let response = GetJsonSync<SPFxAuthToken>(url, body, options);
115
- return _parseAndCacheGetSPFxClientAuthTokenResult(response.result, spfxTokenType);
116
- } catch {
117
- }
118
- return null;
119
- }
@@ -1,13 +0,0 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { normalizeGuid } from '../../helpers/strings';
4
- import { isValidGuid } from '../../helpers/typecheckers';
5
- import { DiscoverTenantInfo } from './discovery';
6
-
7
- test('DiscoverTenantInfo', async t => {
8
- global.XMLHttpRequest = require('xhr2');
9
- let info = await DiscoverTenantInfo("kwizcomdev.sharepoint.com");
10
- await t.test("response not null/undefined", t => assert.notDeepEqual(info, null) && assert.notDeepEqual(info, undefined));
11
- await t.test("has valid guid", t => assert.deepEqual(isValidGuid(info && info.idOrName), true));
12
- await t.test("has correct guid", t => assert.deepEqual(normalizeGuid(info && info.idOrName), normalizeGuid("3bf37eb8-6c20-45a9-aff6-ac72d276f375")));
13
- });
@@ -1,132 +0,0 @@
1
- import { promiseOnce } from "../../helpers/promises";
2
- import { isNullOrEmptyString, isValidGuid } from "../../helpers/typecheckers";
3
- import { AzureEnvironment, ITenantInfo } from "../../types/auth";
4
- import { GetJson, GetJsonSync } from "../rest";
5
-
6
- interface IOpenidConfiguration {
7
- token_endpoint: string;//https://login.microsoftonline.com/7d034656-be03-457d-8d82-60e90cf5f400/oauth2/token
8
- cloud_instance_name: string;//microsoftonline.com
9
- token_endpoint_auth_methods_supported: string[];// ["client_secret_post", "private_key_jwt", "client_secret_basic"]
10
- response_modes_supported: string[];// ["query", "fragment", "form_post"]
11
- response_types_supported: string[];// ["code", "id_token", "code id_token", "token id_token", "token"]
12
- scopes_supported: string[];// ["openid"]
13
- issuer: string;//https://sts.windows.net/7d034656-be03-457d-8d82-60e90cf5f400/
14
- authorization_endpoint: string;//https://login.microsoftonline.com/7d034656-be03-457d-8d82-60e90cf5f400/oauth2/authorize
15
- device_authorization_endpoint: string;//https://login.microsoftonline.com/7d034656-be03-457d-8d82-60e90cf5f400/oauth2/devicecode
16
- end_session_endpoint: string;//https://login.microsoftonline.com/7d034656-be03-457d-8d82-60e90cf5f400/oauth2/logout
17
- userinfo_endpoint: string;//https://login.microsoftonline.com/7d034656-be03-457d-8d82-60e90cf5f400/openid/userinfo
18
- tenant_region_scope: string;//NA
19
- cloud_graph_host_name: string;//graph.windows.net
20
- msgraph_host: string;//graph.microsoft.com
21
- }
22
-
23
- function _getFriendlyName(hostName: string) {
24
- if (hostName.indexOf(".sharepoint.") !== -1) {
25
- let hostParts = hostName.split('.');//should be xxx.sharepoint.com or xxx.sharepoint.us
26
- let firstHostPart = hostParts[0];
27
- let lastHostPart = hostParts[hostParts.length - 1] === "us" || hostParts[hostParts.length - 1] === "de" ? hostParts[hostParts.length - 1] : "com";
28
- if (firstHostPart.endsWith("-admin")) firstHostPart = firstHostPart.substring(0, firstHostPart.length - 6);
29
- return `${firstHostPart}.onmicrosoft.${lastHostPart}`;
30
- }
31
- else {
32
- return hostName;//could be an exchange email domain, or bpos customer
33
- }
34
- }
35
-
36
- function _getOpenIdConfigurationUrl(friendlyName: string) {
37
- return `https://login.microsoftonline.com/${friendlyName}/v2.0/.well-known/openid-configuration`;
38
- }
39
-
40
- function _processOpenidConfiguration(config: IOpenidConfiguration, friendlyName: string) {
41
- let data: ITenantInfo = {
42
- environment: AzureEnvironment.Production,
43
- idOrName: null,
44
- authorityUrl: null,
45
- valid: false
46
- };
47
-
48
- let endpoint = config.token_endpoint;//https://xxxx/{tenant}/....
49
- let tenantId = endpoint.replace("//", "/").split('/')[2];//replace :// with :/ split by / and take the second part.
50
- let instance = config.cloud_instance_name;//microsoftonline.us
51
-
52
- data.environment = GetEnvironmentFromACSEndPoint(instance);
53
- if (!isNullOrEmptyString(tenantId) || isValidGuid(tenantId)) {
54
- data.idOrName = tenantId;
55
- } else {
56
- data.idOrName = friendlyName;
57
- }
58
-
59
- data.authorityUrl = `${GetAzureADLoginEndPoint(data.environment)}/${data.idOrName}`;
60
- data.valid = true;
61
-
62
- return data;
63
- }
64
-
65
- export function DiscoverTenantInfo(hostName: string, sync?: false): Promise<ITenantInfo>
66
- export function DiscoverTenantInfo(hostName: string, sync: true): ITenantInfo
67
- export function DiscoverTenantInfo(hostName: string, sync?: boolean): ITenantInfo | Promise<ITenantInfo> {
68
- hostName = hostName.toLowerCase();
69
-
70
- let friendlyName = _getFriendlyName(hostName);
71
- let url = _getOpenIdConfigurationUrl(friendlyName);
72
-
73
- if (sync === true) {
74
- try {
75
- let response = GetJsonSync<IOpenidConfiguration>(url);
76
- let config = response.result;
77
- let data = _processOpenidConfiguration(config, friendlyName);
78
- return data;
79
- } catch (ex) {
80
- console.log(ex);
81
- }
82
- return null;
83
- } else {
84
- return promiseOnce(`DiscoverTenantInfo|${hostName}`, async () => {
85
- try {
86
- let config = await GetJson<IOpenidConfiguration>(url);
87
- let data = _processOpenidConfiguration(config, friendlyName);
88
- return data;
89
- }
90
- catch (ex) {
91
- console.log(ex);
92
- }
93
- return null;
94
- });
95
- }
96
- }
97
-
98
- export function AutoDiscoverTenantInfo(sync?: false): Promise<ITenantInfo>
99
- export function AutoDiscoverTenantInfo(sync: true): ITenantInfo
100
- export function AutoDiscoverTenantInfo(sync?: boolean): ITenantInfo | Promise<ITenantInfo> {
101
- if (sync === true) {
102
- return DiscoverTenantInfo(window.location.hostname.toLowerCase(), true);
103
- }
104
- return DiscoverTenantInfo(window.location.hostname.toLowerCase(), false);
105
- }
106
-
107
- export function GetEnvironmentFromACSEndPoint(ACSEndPoint: string): AzureEnvironment {
108
- switch (ACSEndPoint) {
109
- case "microsoftonline.us":
110
- return AzureEnvironment.USGovernment;
111
- case "microsoftonline.de":
112
- return AzureEnvironment.Germany;
113
- case "accesscontrol.chinacloudapi.cn":
114
- return AzureEnvironment.China;
115
- case "windows-ppe.net":
116
- return AzureEnvironment.PPE;
117
- case "accesscontrol.windows.net":
118
- default:
119
- return AzureEnvironment.Production;
120
- }
121
- }
122
- export function GetAzureADLoginEndPoint(environment: AzureEnvironment): string {
123
- switch (environment) {
124
- case AzureEnvironment.Germany: return "https://login.microsoftonline.de";
125
- case AzureEnvironment.China: return "https://login.chinacloudapi.cn";
126
- case AzureEnvironment.USGovernment: return "https://login.microsoftonline.us";
127
- case AzureEnvironment.PPE: return "https://login.windows-ppe.net";
128
- case AzureEnvironment.Production:
129
- default:
130
- return "https://login.microsoftonline.com";
131
- }
132
- }
@@ -1,2 +0,0 @@
1
- export * from './common';
2
- export * from './discovery';
@@ -1,28 +0,0 @@
1
- import { blobToBase64 } from "../helpers/base64";
2
- import { isNullOrEmptyString } from "../helpers/typecheckers";
3
- import { GetJson } from "./rest";
4
- import { GetFile } from "./sharepoint.rest/file.folder";
5
-
6
- /** if the file is in SharePoint, provide a siteRelativeUrl so that we can get the file value via REST api to avoid CORS error when accessing a file on the site from within the app web */
7
- export async function imageToBase64(imageSrc: string, siteRelativeUrl?: string): Promise<string> {
8
- try {
9
- let fileBlob: Blob = null;
10
- if (!isNullOrEmptyString(siteRelativeUrl) && imageSrc.toLowerCase().indexOf(siteRelativeUrl.toLowerCase()) >= 0) {
11
- let spFile = await GetFile<Blob>(siteRelativeUrl, imageSrc, true, "blob");
12
- if (spFile && spFile.Exists)
13
- fileBlob = spFile.Content;
14
- }
15
-
16
- //try simple rest if the first option failed
17
- if (fileBlob === null) {
18
- fileBlob = await GetJson<Blob>(imageSrc, null, { responseType: "blob", allowCache: true });
19
- }
20
-
21
- if (fileBlob) {
22
- let base64 = await blobToBase64(fileBlob);
23
- return base64;
24
- }
25
- } catch (e) {
26
- }
27
- return null;
28
- }