@kwiz/common 1.0.132 → 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 (98) hide show
  1. package/package.json +1 -1
  2. package/.github/workflows/npm-publish.yml +0 -24
  3. package/src/_dependencies.ts +0 -13
  4. package/src/config.ts +0 -19
  5. package/src/exports-index.ts +0 -4
  6. package/src/helpers/Guid.ts +0 -182
  7. package/src/helpers/base64.ts +0 -174
  8. package/src/helpers/browser.test.js +0 -13
  9. package/src/helpers/browser.ts +0 -1505
  10. package/src/helpers/browserinfo.ts +0 -293
  11. package/src/helpers/collections.base.test.js +0 -26
  12. package/src/helpers/collections.base.ts +0 -438
  13. package/src/helpers/collections.ts +0 -108
  14. package/src/helpers/color.ts +0 -55
  15. package/src/helpers/cookies.ts +0 -60
  16. package/src/helpers/date.test.js +0 -120
  17. package/src/helpers/date.ts +0 -189
  18. package/src/helpers/debug.ts +0 -187
  19. package/src/helpers/diagrams.ts +0 -44
  20. package/src/helpers/emails.ts +0 -7
  21. package/src/helpers/eval.ts +0 -5
  22. package/src/helpers/exports-index.ts +0 -30
  23. package/src/helpers/file.test.js +0 -51
  24. package/src/helpers/file.ts +0 -64
  25. package/src/helpers/flatted.ts +0 -150
  26. package/src/helpers/functions.ts +0 -17
  27. package/src/helpers/graph/calendar.types.ts +0 -11
  28. package/src/helpers/graph/exports-index.ts +0 -1
  29. package/src/helpers/http.ts +0 -70
  30. package/src/helpers/images.ts +0 -23
  31. package/src/helpers/json.ts +0 -45
  32. package/src/helpers/md5.ts +0 -190
  33. package/src/helpers/objects.test.js +0 -34
  34. package/src/helpers/objects.ts +0 -275
  35. package/src/helpers/promises.test.js +0 -38
  36. package/src/helpers/promises.ts +0 -166
  37. package/src/helpers/random.ts +0 -27
  38. package/src/helpers/scheduler/exports-index.ts +0 -1
  39. package/src/helpers/scheduler/scheduler.test.js +0 -104
  40. package/src/helpers/scheduler/scheduler.ts +0 -132
  41. package/src/helpers/sharepoint.ts +0 -797
  42. package/src/helpers/strings.test.js +0 -123
  43. package/src/helpers/strings.ts +0 -338
  44. package/src/helpers/typecheckers.test.js +0 -35
  45. package/src/helpers/typecheckers.ts +0 -267
  46. package/src/helpers/url.test.js +0 -44
  47. package/src/helpers/url.ts +0 -208
  48. package/src/helpers/urlhelper.ts +0 -112
  49. package/src/index.ts +0 -6
  50. package/src/types/auth.ts +0 -63
  51. package/src/types/common.types.ts +0 -16
  52. package/src/types/exports-index.ts +0 -15
  53. package/src/types/flatted.types.ts +0 -60
  54. package/src/types/globals.types.ts +0 -7
  55. package/src/types/graph/calendar.types.ts +0 -81
  56. package/src/types/graph/exports-index.ts +0 -1
  57. package/src/types/knownscript.types.ts +0 -19
  58. package/src/types/libs/datajs.types.ts +0 -29
  59. package/src/types/libs/exports-index.ts +0 -3
  60. package/src/types/libs/ics.types.ts +0 -31
  61. package/src/types/libs/msal.types.ts +0 -58
  62. package/src/types/locales.ts +0 -126
  63. package/src/types/localstoragecache.types.ts +0 -9
  64. package/src/types/location.types.ts +0 -28
  65. package/src/types/moment.ts +0 -12
  66. package/src/types/regex.types.ts +0 -17
  67. package/src/types/rest.types.ts +0 -96
  68. package/src/types/sharepoint.types.ts +0 -1467
  69. package/src/types/sharepoint.utils.types.ts +0 -307
  70. package/src/utils/auth/common.ts +0 -119
  71. package/src/utils/auth/discovery.test.js +0 -13
  72. package/src/utils/auth/discovery.ts +0 -132
  73. package/src/utils/auth/exports-index.ts +0 -2
  74. package/src/utils/base64.ts +0 -28
  75. package/src/utils/consolelogger.ts +0 -334
  76. package/src/utils/date.ts +0 -173
  77. package/src/utils/emails.ts +0 -25
  78. package/src/utils/exports-index.ts +0 -11
  79. package/src/utils/knownscript.ts +0 -287
  80. package/src/utils/localstoragecache.ts +0 -447
  81. package/src/utils/rest.ts +0 -502
  82. package/src/utils/script.ts +0 -171
  83. package/src/utils/sharepoint.rest/common.ts +0 -160
  84. package/src/utils/sharepoint.rest/date.ts +0 -63
  85. package/src/utils/sharepoint.rest/exports-index.ts +0 -11
  86. package/src/utils/sharepoint.rest/file.folder.ts +0 -685
  87. package/src/utils/sharepoint.rest/item.ts +0 -547
  88. package/src/utils/sharepoint.rest/list.ts +0 -1572
  89. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -775
  90. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -275
  91. package/src/utils/sharepoint.rest/listutils/common.ts +0 -207
  92. package/src/utils/sharepoint.rest/listutils/exports-index.ts +0 -3
  93. package/src/utils/sharepoint.rest/location.ts +0 -142
  94. package/src/utils/sharepoint.rest/navigation-links.ts +0 -87
  95. package/src/utils/sharepoint.rest/user-search.ts +0 -253
  96. package/src/utils/sharepoint.rest/user.ts +0 -559
  97. package/src/utils/sharepoint.rest/web.ts +0 -1385
  98. package/src/utils/sod.ts +0 -195
@@ -1,160 +0,0 @@
1
- import { jsonParse } from "../../helpers/json";
2
- import { isNullOrEmptyString, isNullOrUndefined, isString, isValidGuid } from "../../helpers/typecheckers";
3
- import { makeServerRelativeUrl, normalizeUrl } from "../../helpers/url";
4
- import { IDictionary } from "../../types/common.types";
5
- import { IRestError } from "../../types/rest.types";
6
- import { FieldTypeAsString, IFieldInfoEX, IFieldTaxonomyInfo } from "../../types/sharepoint.types";
7
- import { ISPRestError } from "../../types/sharepoint.utils.types";
8
- import { ConsoleLogger } from "../consolelogger";
9
- import { getCacheItem, setCacheItem } from "../localstoragecache";
10
- import { mediumLocalCache } from "../rest";
11
- import { GetWebIdSync, GetWebInfoSync } from "./web";
12
-
13
- const logger = ConsoleLogger.get("sharepoint.rest/common");
14
-
15
- export const LIST_SELECT = `ListExperienceOptions,EffectiveBasePermissions,Description,Title,EnableAttachments,EnableModeration,BaseTemplate,BaseType,Id,Hidden,IsApplicationList,IsPrivate,IsCatalog,ImageUrl,ItemCount,ParentWebUrl,EntityTypeName,DefaultViewUrl,ParentWeb/Id,ParentWeb/Title`;
16
- export const LIST_EXPAND = `ParentWeb/Id,ParentWeb/Title`;
17
- export const WEB_SELECT = "Title,ServerRelativeUrl,Id,WebTemplate,Description,SiteLogoUrl";
18
- export const CONTENT_TYPES_SELECT = "Name,Description,StringId,Group,Hidden,ReadOnly,NewFormUrl,DisplayFormUrl,EditFormUrl,Sealed,MobileDisplayFormUrl,MobileNewFormUrl,MobileEditFormUrl,NewFormTemplateName,DisplayFormTemplateName,EditFormTemplateName";
19
- export const CONTENT_TYPES_SELECT_WITH_FIELDS = `${CONTENT_TYPES_SELECT},Fields`;
20
-
21
- export function hasGlobalContext() {
22
- //_spPageContextInfo.webServerRelativeUrl can be empty string
23
- return typeof (_spPageContextInfo) !== "undefined" && isString(_spPageContextInfo.webServerRelativeUrl);
24
- }
25
-
26
- export function GetFileSiteUrl(fileUrl: string): string {
27
- let siteUrl: string;
28
- let urlParts = fileUrl.split('/');
29
- if (urlParts[urlParts.length - 1].indexOf('.') > 0)//file name
30
- urlParts.pop();//file name
31
-
32
- let key = "GetSiteUrl|" + urlParts.join("/").toLowerCase();
33
- siteUrl = getCacheItem<string>(key);
34
- if (isNullOrUndefined(siteUrl)) {
35
- while (!isValidGuid(GetWebIdSync(urlParts.join('/'))))
36
- urlParts.pop();
37
-
38
- siteUrl = normalizeUrl(urlParts.join('/'));
39
- setCacheItem(key, siteUrl, mediumLocalCache.localStorageExpiration);//keep for 15 minutes
40
- }
41
- //must end with / otherwise root sites will return "" and we will think there is no site url.
42
- return makeServerRelativeUrl(normalizeUrl(siteUrl, true));
43
- }
44
-
45
- /** gets a site URL or null, returns the current web URL or siteUrl as relative URL - end with /
46
- * If you send a guid - it will look for a site with that ID in the current context site collection
47
- */
48
- export function GetSiteUrl(siteUrlOrId?: string): string {
49
- let siteUrl: string;
50
- if (isNullOrUndefined(siteUrlOrId)) {
51
- if (hasGlobalContext()) {
52
- siteUrl = _spPageContextInfo.webServerRelativeUrl;
53
- if (_spPageContextInfo.isAppWeb)//#1300 if in a classic app sub-site
54
- siteUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/"));
55
- }
56
- else {
57
- siteUrl = GetFileSiteUrl(window.location.pathname);
58
- }
59
- }
60
- else if (isValidGuid(siteUrlOrId)) {
61
- //GetWebInfoSync calls GetSiteUrl recursively, but with null should not get in here
62
- let webInfo = GetWebInfoSync(null, siteUrlOrId);
63
- siteUrl = webInfo.ServerRelativeUrl;
64
- }
65
- else siteUrl = siteUrlOrId;
66
-
67
- //must end with / otherwise root sites will return "" and we will think there is no site url.
68
- return makeServerRelativeUrl(normalizeUrl(siteUrl, true));
69
- }
70
-
71
- /** gets a site url, returns its REST _api url */
72
- export function GetRestBaseUrl(siteUrl: string): string {
73
- siteUrl = GetSiteUrl(siteUrl);
74
- return siteUrl + '_api';
75
- }
76
-
77
- /** Get the field internal name as you can find it in item.FieldValuesAsText[name] (Or FieldValuesForEdit) */
78
- export function DecodeFieldValuesAsTextKey(key: string): string {
79
- return key.replace(/_x005f_/g, "_").replace('OData__', '_');
80
- }
81
-
82
- /** Replaces _ with _x005f_, except OData_ at the start */
83
- export function EncodeFieldValuesAsTextKey(key: string): string {
84
- return key.replace('OData_', '~').replace(/_/g, "_x005f_").replace('~', 'OData_');
85
- }
86
-
87
- /** Gets REST FieldValuesAsText or FieldValuesForEdit and fix their column names so that you can get a field value by its internal name */
88
- export function DecodeFieldValuesAsText(FieldValuesAsText: IDictionary<string>) {
89
- return DecodeFieldValuesForEdit(FieldValuesAsText);
90
- }
91
- /** Gets REST FieldValuesAsText or FieldValuesForEdit and fix their column names so that you can get a field value by its internal name */
92
- export function DecodeFieldValuesForEdit(FieldValuesForEdit: IDictionary<string>) {
93
- let result: IDictionary<string> = {};
94
- Object.keys(FieldValuesForEdit).forEach(key => {
95
- result[DecodeFieldValuesAsTextKey(key)] = FieldValuesForEdit[key];
96
- });
97
- return result;
98
- }
99
-
100
- /** Get the field internal name as you can find it in the item[name] to get raw values */
101
- export function GetFieldNameFromRawValues(
102
- field: { InternalName: string; TypeAsString: FieldTypeAsString; },
103
- //ISSUE: 1250
104
- options: {
105
- excludeIdFromName: boolean
106
- } = {
107
- excludeIdFromName: false
108
- }): string {
109
- let fieldName = field.InternalName;
110
- if (options.excludeIdFromName !== true && (field.TypeAsString === "User" ||
111
- field.TypeAsString === "UserMulti" ||
112
- field.TypeAsString === "Lookup" ||
113
- field.TypeAsString === "LookupMulti" ||
114
- field.InternalName === "ContentType")) {
115
- fieldName = fieldName += "Id";
116
- }
117
-
118
- //issue 6698 fields that are too short will encode their first letter, and will start with _. this will add OData_ as a prefix in REST
119
- //Issue 336 _EndDate > OData__EndDate
120
- if (fieldName.startsWith('_')) {
121
- fieldName = "OData_" + fieldName;
122
- }
123
- return fieldName;
124
- }
125
-
126
- /** Get the field name to set on the item update REST request */
127
- export function getFieldNameForUpdate(field: IFieldInfoEX): string {
128
- if (field.TypeAsString === "TaxonomyFieldTypeMulti") {
129
- //Updating multi taxonomy value is allowed as string to the associated hidden text field
130
- return (field as IFieldTaxonomyInfo).HiddenMultiValueFieldName;
131
- }
132
-
133
- return GetFieldNameFromRawValues(field);
134
- }
135
-
136
- export function __isIRestError(e: any): e is IRestError {
137
- let x = e as IRestError;
138
- return !isNullOrUndefined(x) && !isNullOrUndefined(x.xhr) && isString(x.message);
139
- }
140
- /** extract the error message from a SharePoint REST failed request */
141
- export function __getSPRestErrorData(restError: IRestError) {
142
- let code = "Unknown";
143
- let errorMessage = "Unspecified error";
144
- if (restError && restError.message) errorMessage = restError.message;
145
- if (restError && restError.xhr && !isNullOrEmptyString(restError.xhr.responseText)) {
146
- let errorData = jsonParse<{ error: { code: string; message: { value: string; }; }; }>(restError.xhr.responseText);
147
- let error = errorData && errorData.error;
148
- if (!error && errorData)//in minimal rest - error is in "odata.error"
149
- error = errorData && errorData["odata.error"];
150
-
151
- if (error) {
152
- if (error && error.message && error.message.value)
153
- errorMessage = error.message.value;
154
- if (error && error.code)
155
- code = error.code;
156
- }
157
- }
158
- logger.error(errorMessage);
159
- return { code: code, message: errorMessage } as ISPRestError;
160
- }
@@ -1,63 +0,0 @@
1
- import { isISODate, isISODateUTC } from "../../helpers/date";
2
- import { isDate, isNullOrEmptyString, isNullOrUndefined } from "../../helpers/typecheckers";
3
- import { DateOrNull } from "../../types/common.types";
4
- import { toIsoDateFormat } from "../date";
5
- import { LocaleKnownScript } from "../knownscript";
6
- import { SPServerLocalTimeToUTCSync } from "./web";
7
-
8
- function _SPServerLocalTimeToUTC(dateValueStr: string) {
9
- //yyyy-MM-ddTHH:mm or SPServerLocalTime (5/27/2021 11:34) to UTC
10
- let utcTimeValue = SPServerLocalTimeToUTCSync(_spPageContextInfo.webServerRelativeUrl, dateValueStr);
11
-
12
- if (!isNullOrEmptyString(utcTimeValue)) {
13
- return new Date(utcTimeValue);
14
- }
15
- return null;
16
- }
17
-
18
- export function parseDate(value: string | Date): DateOrNull {
19
- if (isNullOrUndefined(value) || (isNullOrEmptyString(value) && !isDate(value))) {
20
- return null;
21
- }
22
-
23
- let dateValueStr = isDate(value) ? value.toISOString() : value;
24
-
25
- var valueAsDate: DateOrNull = null;
26
-
27
- if (isISODateUTC(dateValueStr)) {
28
- valueAsDate = new Date(dateValueStr);
29
- } else if (isISODate(dateValueStr)) {
30
- //yyyy-MM-ddTHH:mm or SPServerLocalTime (5/27/2021 11:34) to UTC
31
- valueAsDate = _SPServerLocalTimeToUTC(dateValueStr);
32
- } else {
33
- //Don't think this is necessary because the SPServerLocalTimeToUTCSync can accept date strings in non ISO format (5/27/2021 11:34)
34
- var dateParts: string[] = dateValueStr.split(" ");
35
- if (dateParts.length) {
36
- let locales = LocaleKnownScript.loadSync();
37
-
38
- valueAsDate = locales.ParseDate(dateValueStr);
39
- dateValueStr = toIsoDateFormat(valueAsDate, { omitZ: true });
40
- valueAsDate = _SPServerLocalTimeToUTC(dateValueStr);
41
-
42
- if (valueAsDate instanceof Date && dateParts.length === 2) {
43
- var time = dateParts[1];
44
- if (time.length) {
45
- var timeParts = locales.GetCurrentCulture() ? locales.GetCurrentCulture().dateTimeFormat.TimeSeparator : ":";
46
- if (timeParts.length === 2) {
47
- var hours = Number(timeParts[0]);
48
- var minutes = Number(timeParts[1]);
49
-
50
- valueAsDate.setHours(hours);
51
- valueAsDate.setMinutes(minutes);
52
- }
53
- }
54
- }
55
- }
56
- }
57
-
58
- if (!valueAsDate) {
59
- valueAsDate = new Date(dateValueStr);
60
- }
61
-
62
- return isDate(valueAsDate) ? valueAsDate : null;
63
- }
@@ -1,11 +0,0 @@
1
- export * from './listutils/exports-index';
2
- export * from './common';
3
- export * from './date';
4
- export * from './file.folder';
5
- export * from './item';
6
- export * from './list';
7
- export * from './location';
8
- export * from './navigation-links';
9
- export * from './user-search';
10
- export * from './user';
11
- export * from './web';