@kwiz/common 1.0.107 → 1.0.109

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 (116) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/helpers/browser.js +9 -5
  6. package/lib/cjs/helpers/browser.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/types/libs/msal.types.js.map +1 -1
  9. package/lib/cjs/types/sharepoint.utils.types.js +9 -1
  10. package/lib/cjs/types/sharepoint.utils.types.js.map +1 -1
  11. package/lib/cjs/utils/sharepoint.rest/file.folder.js +4 -4
  12. package/lib/cjs/utils/sharepoint.rest/file.folder.js.map +1 -1
  13. package/lib/cjs/utils/sharepoint.rest/list.js +60 -1
  14. package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
  15. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  16. package/lib/esm/helpers/browser.js +9 -5
  17. package/lib/esm/helpers/browser.js.map +1 -1
  18. package/lib/esm/types/libs/msal.types.js +26 -26
  19. package/lib/esm/types/libs/msal.types.js.map +1 -1
  20. package/lib/esm/types/sharepoint.utils.types.js +8 -0
  21. package/lib/esm/types/sharepoint.utils.types.js.map +1 -1
  22. package/lib/esm/utils/sharepoint.rest/file.folder.js +4 -4
  23. package/lib/esm/utils/sharepoint.rest/file.folder.js.map +1 -1
  24. package/lib/esm/utils/sharepoint.rest/list.js +57 -0
  25. package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
  26. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  27. package/lib/types/types/libs/msal.types.d.ts +8 -3
  28. package/lib/types/types/sharepoint.utils.types.d.ts +17 -0
  29. package/lib/types/utils/sharepoint.rest/list.d.ts +7 -1
  30. package/package.json +81 -81
  31. package/readme.md +17 -17
  32. package/src/_dependencies.ts +12 -12
  33. package/src/config.ts +17 -17
  34. package/src/helpers/Guid.ts +181 -181
  35. package/src/helpers/base64.ts +173 -173
  36. package/src/helpers/browser.test.js +13 -13
  37. package/src/helpers/browser.ts +1448 -1448
  38. package/src/helpers/browserinfo.ts +292 -292
  39. package/src/helpers/collections.base.test.js +25 -25
  40. package/src/helpers/collections.base.ts +437 -437
  41. package/src/helpers/collections.ts +107 -107
  42. package/src/helpers/color.ts +54 -54
  43. package/src/helpers/cookies.ts +59 -59
  44. package/src/helpers/date.test.js +119 -119
  45. package/src/helpers/date.ts +188 -188
  46. package/src/helpers/debug.ts +186 -186
  47. package/src/helpers/diagrams.ts +43 -43
  48. package/src/helpers/emails.ts +6 -6
  49. package/src/helpers/eval.ts +5 -5
  50. package/src/helpers/file.test.js +50 -50
  51. package/src/helpers/file.ts +63 -63
  52. package/src/helpers/flatted.ts +149 -149
  53. package/src/helpers/functions.ts +16 -16
  54. package/src/helpers/graph/calendar.types.ts +10 -10
  55. package/src/helpers/http.ts +69 -69
  56. package/src/helpers/images.ts +22 -22
  57. package/src/helpers/json.ts +44 -44
  58. package/src/helpers/md5.ts +189 -189
  59. package/src/helpers/objects.test.js +33 -33
  60. package/src/helpers/objects.ts +274 -274
  61. package/src/helpers/promises.test.js +37 -37
  62. package/src/helpers/promises.ts +165 -165
  63. package/src/helpers/random.ts +27 -27
  64. package/src/helpers/scheduler/scheduler.test.js +103 -103
  65. package/src/helpers/scheduler/scheduler.ts +131 -131
  66. package/src/helpers/sharepoint.ts +785 -785
  67. package/src/helpers/strings.test.js +122 -122
  68. package/src/helpers/strings.ts +337 -337
  69. package/src/helpers/typecheckers.test.js +34 -34
  70. package/src/helpers/typecheckers.ts +266 -266
  71. package/src/helpers/url.test.js +43 -43
  72. package/src/helpers/url.ts +207 -207
  73. package/src/helpers/urlhelper.ts +111 -111
  74. package/src/index.ts +6 -6
  75. package/src/types/auth.ts +54 -54
  76. package/src/types/common.types.ts +15 -15
  77. package/src/types/flatted.types.ts +59 -59
  78. package/src/types/globals.types.ts +6 -6
  79. package/src/types/graph/calendar.types.ts +80 -80
  80. package/src/types/knownscript.types.ts +18 -18
  81. package/src/types/libs/datajs.types.ts +28 -28
  82. package/src/types/libs/ics.types.ts +30 -30
  83. package/src/types/libs/msal.types.ts +57 -49
  84. package/src/types/locales.ts +125 -125
  85. package/src/types/localstoragecache.types.ts +8 -8
  86. package/src/types/location.types.ts +27 -27
  87. package/src/types/moment.ts +11 -11
  88. package/src/types/regex.types.ts +16 -16
  89. package/src/types/rest.types.ts +95 -95
  90. package/src/types/sharepoint.types.ts +1466 -1466
  91. package/src/types/sharepoint.utils.types.ts +306 -287
  92. package/src/utils/auth/common.ts +74 -74
  93. package/src/utils/auth/discovery.test.js +12 -12
  94. package/src/utils/auth/discovery.ts +132 -132
  95. package/src/utils/base64.ts +27 -27
  96. package/src/utils/consolelogger.ts +320 -320
  97. package/src/utils/date.ts +172 -172
  98. package/src/utils/emails.ts +24 -24
  99. package/src/utils/knownscript.ts +286 -286
  100. package/src/utils/localstoragecache.ts +446 -446
  101. package/src/utils/rest.ts +501 -501
  102. package/src/utils/script.ts +170 -170
  103. package/src/utils/sharepoint.rest/common.ts +154 -154
  104. package/src/utils/sharepoint.rest/date.ts +62 -62
  105. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  106. package/src/utils/sharepoint.rest/item.ts +547 -547
  107. package/src/utils/sharepoint.rest/list.ts +1548 -1482
  108. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  109. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  110. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  111. package/src/utils/sharepoint.rest/location.ts +141 -141
  112. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  113. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  114. package/src/utils/sharepoint.rest/user.ts +491 -491
  115. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  116. package/src/utils/sod.ts +194 -194
@@ -1,126 +1,126 @@
1
- export type SysNumberFormatType = {
2
- CurrencyDecimalDigits: number;
3
- CurrencyDecimalSeparator: string;
4
- IsReadOnly: boolean;
5
- CurrencyGroupSizes: number[];
6
- NumberGroupSizes: number[];
7
- PercentGroupSizes: number[];
8
- CurrencyGroupSeparator: string;
9
- CurrencySymbol: string;
10
- NaNSymbol: string;
11
- CurrencyNegativePattern: number;
12
- NumberNegativePattern: number;
13
- PercentPositivePattern: number;
14
- PercentNegativePattern: number;
15
- NegativeInfinitySymbol: string;
16
- NegativeSign: string;
17
- NumberDecimalDigits: number;
18
- NumberDecimalSeparator: string;
19
- NumberGroupSeparator: string;
20
- CurrencyPositivePattern: number;
21
- PositiveInfinitySymbol: string;
22
- PositiveSign: string;
23
- PercentDecimalDigits: number;
24
- PercentDecimalSeparator: string;
25
- PercentGroupSeparator: string;
26
- PercentSymbol: string;
27
- PerMilleSymbol: string;
28
- NativeDigits: string[];
29
- DigitSubstitution: number;
30
- };
31
-
32
- export type SysDateFormatType = {
33
- AMDesignator: string;
34
- Calendar: {
35
- MinSupportedDateTime: string;
36
- MaxSupportedDateTime: string;
37
- AlgorithmType: number;
38
- CalendarType: number;
39
- Eras: number[];
40
- TwoDigitYearMax: number;
41
- IsReadOnly: boolean;
42
- };
43
- DateSeparator: string;
44
- FirstDayOfWeek: number;
45
- CalendarWeekRule: number;
46
- FullDateTimePattern: string;
47
- LongDatePattern: string;
48
- LongTimePattern: string;
49
- MonthDayPattern: string;
50
- PMDesignator: string;
51
- RFC1123Pattern: string;
52
- ShortDatePattern: string;
53
- ShortTimePattern: string;
54
- SortableDateTimePattern: string;
55
- TimeSeparator: string;
56
- UniversalSortableDateTimePattern: string;
57
- YearMonthPattern: string;
58
- AbbreviatedDayNames: string[];
59
- ShortestDayNames: string[];
60
- DayNames: string[];
61
- AbbreviatedMonthNames: string[];
62
- MonthNames: string[];
63
- IsReadOnly: boolean;
64
- NativeCalendarName: string;
65
- AbbreviatedMonthGenitiveNames: string[];
66
- MonthGenitiveNames: string[];
67
- eras: any[];
68
- };
69
- export type CultureInfoType = {
70
- LCID: number;
71
- name: string;
72
- numberFormat: SysNumberFormatType;
73
- dateTimeFormat: SysDateFormatType;
74
- ShortDatePattern?: string;
75
- ShortTimePattern?: string;
76
- DateSeparator?: string;
77
- TimeSeparator?: string;
78
- CurrencySymbol?: string;
79
- PercentSymbol?: string;
80
- NumberDecimalSeparator?: string;
81
- NumberGroupSeparator?: string;
82
- };
83
-
84
- export interface IKLocales {
85
- getCultureNameOrLCIDFromContextInfo(s: number): string | number;
86
- GetCulture(cultureNameOrLCID: string | number): CultureInfoType;
87
- GetCurrentCulture(): CultureInfoType;
88
- SetCurrentCulture(culture: CultureInfoType);
89
- ParseDate(strDate: string, culture?: CultureInfoType): Date;
90
- /** default format: date only */
91
- DateToString(dateObj: Date, culture: CultureInfoType, format?: { includeDate?: boolean; includeTime?: boolean; }): string;
92
- ParseNumber(strNumber: string, culture?: CultureInfoType): number;
93
- /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100. */
94
- NumberToString(num: number,
95
- /** current web cutlure, default=GetCurrentCulture */
96
- webCulture?: CultureInfoType,
97
- numFormat?: {
98
- /** default=false */
99
- includeGroupSeparator?: boolean;
100
- /** default=false */
101
- isPercent?: boolean;
102
- /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100, default=false */
103
- isPercentAsWholeNumbers?: boolean;
104
- /** default=false */
105
- isCurrency?: boolean;
106
- /** default=webCulture.LCID */
107
- currencyLocaleId?: number;
108
- /** default=false */
109
- numberOnly?: boolean;
110
- }): string;
111
- IsValidNumber(strNumber: string, culture: CultureInfoType): boolean;
112
- }
113
-
114
- declare global {
115
- interface Date {
116
- /**
117
- * Formats a date by using the invariant (culture-independent) culture.
118
- * @deprecated this is only available when loading KLocals known script
119
- */
120
- format(format: string): string;
121
- }
122
-
123
- interface IKWizComGlobals {
124
- kLocales?: IKLocales;
125
- }
1
+ export type SysNumberFormatType = {
2
+ CurrencyDecimalDigits: number;
3
+ CurrencyDecimalSeparator: string;
4
+ IsReadOnly: boolean;
5
+ CurrencyGroupSizes: number[];
6
+ NumberGroupSizes: number[];
7
+ PercentGroupSizes: number[];
8
+ CurrencyGroupSeparator: string;
9
+ CurrencySymbol: string;
10
+ NaNSymbol: string;
11
+ CurrencyNegativePattern: number;
12
+ NumberNegativePattern: number;
13
+ PercentPositivePattern: number;
14
+ PercentNegativePattern: number;
15
+ NegativeInfinitySymbol: string;
16
+ NegativeSign: string;
17
+ NumberDecimalDigits: number;
18
+ NumberDecimalSeparator: string;
19
+ NumberGroupSeparator: string;
20
+ CurrencyPositivePattern: number;
21
+ PositiveInfinitySymbol: string;
22
+ PositiveSign: string;
23
+ PercentDecimalDigits: number;
24
+ PercentDecimalSeparator: string;
25
+ PercentGroupSeparator: string;
26
+ PercentSymbol: string;
27
+ PerMilleSymbol: string;
28
+ NativeDigits: string[];
29
+ DigitSubstitution: number;
30
+ };
31
+
32
+ export type SysDateFormatType = {
33
+ AMDesignator: string;
34
+ Calendar: {
35
+ MinSupportedDateTime: string;
36
+ MaxSupportedDateTime: string;
37
+ AlgorithmType: number;
38
+ CalendarType: number;
39
+ Eras: number[];
40
+ TwoDigitYearMax: number;
41
+ IsReadOnly: boolean;
42
+ };
43
+ DateSeparator: string;
44
+ FirstDayOfWeek: number;
45
+ CalendarWeekRule: number;
46
+ FullDateTimePattern: string;
47
+ LongDatePattern: string;
48
+ LongTimePattern: string;
49
+ MonthDayPattern: string;
50
+ PMDesignator: string;
51
+ RFC1123Pattern: string;
52
+ ShortDatePattern: string;
53
+ ShortTimePattern: string;
54
+ SortableDateTimePattern: string;
55
+ TimeSeparator: string;
56
+ UniversalSortableDateTimePattern: string;
57
+ YearMonthPattern: string;
58
+ AbbreviatedDayNames: string[];
59
+ ShortestDayNames: string[];
60
+ DayNames: string[];
61
+ AbbreviatedMonthNames: string[];
62
+ MonthNames: string[];
63
+ IsReadOnly: boolean;
64
+ NativeCalendarName: string;
65
+ AbbreviatedMonthGenitiveNames: string[];
66
+ MonthGenitiveNames: string[];
67
+ eras: any[];
68
+ };
69
+ export type CultureInfoType = {
70
+ LCID: number;
71
+ name: string;
72
+ numberFormat: SysNumberFormatType;
73
+ dateTimeFormat: SysDateFormatType;
74
+ ShortDatePattern?: string;
75
+ ShortTimePattern?: string;
76
+ DateSeparator?: string;
77
+ TimeSeparator?: string;
78
+ CurrencySymbol?: string;
79
+ PercentSymbol?: string;
80
+ NumberDecimalSeparator?: string;
81
+ NumberGroupSeparator?: string;
82
+ };
83
+
84
+ export interface IKLocales {
85
+ getCultureNameOrLCIDFromContextInfo(s: number): string | number;
86
+ GetCulture(cultureNameOrLCID: string | number): CultureInfoType;
87
+ GetCurrentCulture(): CultureInfoType;
88
+ SetCurrentCulture(culture: CultureInfoType);
89
+ ParseDate(strDate: string, culture?: CultureInfoType): Date;
90
+ /** default format: date only */
91
+ DateToString(dateObj: Date, culture: CultureInfoType, format?: { includeDate?: boolean; includeTime?: boolean; }): string;
92
+ ParseNumber(strNumber: string, culture?: CultureInfoType): number;
93
+ /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100. */
94
+ NumberToString(num: number,
95
+ /** current web cutlure, default=GetCurrentCulture */
96
+ webCulture?: CultureInfoType,
97
+ numFormat?: {
98
+ /** default=false */
99
+ includeGroupSeparator?: boolean;
100
+ /** default=false */
101
+ isPercent?: boolean;
102
+ /** isPercentAsWholeNumbers means a percent number that is 1 to 100, not 0-1. will not multiply it by 100, default=false */
103
+ isPercentAsWholeNumbers?: boolean;
104
+ /** default=false */
105
+ isCurrency?: boolean;
106
+ /** default=webCulture.LCID */
107
+ currencyLocaleId?: number;
108
+ /** default=false */
109
+ numberOnly?: boolean;
110
+ }): string;
111
+ IsValidNumber(strNumber: string, culture: CultureInfoType): boolean;
112
+ }
113
+
114
+ declare global {
115
+ interface Date {
116
+ /**
117
+ * Formats a date by using the invariant (culture-independent) culture.
118
+ * @deprecated this is only available when loading KLocals known script
119
+ */
120
+ format(format: string): string;
121
+ }
122
+
123
+ interface IKWizComGlobals {
124
+ kLocales?: IKLocales;
125
+ }
126
126
  }
@@ -1,9 +1,9 @@
1
- //#region Cache Service
2
- export interface ILocalStorageCacheLifetime {
3
- seconds?: number;
4
- minutes?: number;
5
- hours?: number;
6
- days?: number;
7
- months?: number;
8
- years?: number;
1
+ //#region Cache Service
2
+ export interface ILocalStorageCacheLifetime {
3
+ seconds?: number;
4
+ minutes?: number;
5
+ hours?: number;
6
+ days?: number;
7
+ months?: number;
8
+ years?: number;
9
9
  }
@@ -1,28 +1,28 @@
1
- export type IMeetingLocationEntityType = "Custom" | "Default" | "ConferenceRoom" | "HomeAddress" | "BusinessAddress"
2
- | "GeoCoordinates" | "StreetAddress" | "Hotel" | "Restaurant" | "LocalBusiness" | "PostalAddress";
3
-
4
- export interface IMeetingLocationAddress {
5
- Street: string;
6
- City: string;
7
- State: string;
8
- CountryOrRegion: string;
9
- PostalCode: string;
10
- }
11
-
12
- export interface IMeetingLocationCoordinates {
13
- Latitude: number;
14
- Longitude: number;
15
- }
16
-
17
- /** Represents location information of an event.
18
- * Similar to https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0/ */
19
- export interface IMeetingLocation {
20
- Address?: IMeetingLocationAddress,
21
- Coordinates?: IMeetingLocationCoordinates,
22
- DisplayName: string;
23
- EntityType?: IMeetingLocationEntityType;
24
- IsPreviouslyUsed?: boolean;
25
- LocationSource?: string;
26
- LocationUri?: string;
27
- UniqueId?: string;
1
+ export type IMeetingLocationEntityType = "Custom" | "Default" | "ConferenceRoom" | "HomeAddress" | "BusinessAddress"
2
+ | "GeoCoordinates" | "StreetAddress" | "Hotel" | "Restaurant" | "LocalBusiness" | "PostalAddress";
3
+
4
+ export interface IMeetingLocationAddress {
5
+ Street: string;
6
+ City: string;
7
+ State: string;
8
+ CountryOrRegion: string;
9
+ PostalCode: string;
10
+ }
11
+
12
+ export interface IMeetingLocationCoordinates {
13
+ Latitude: number;
14
+ Longitude: number;
15
+ }
16
+
17
+ /** Represents location information of an event.
18
+ * Similar to https://learn.microsoft.com/en-us/graph/api/resources/location?view=graph-rest-1.0/ */
19
+ export interface IMeetingLocation {
20
+ Address?: IMeetingLocationAddress,
21
+ Coordinates?: IMeetingLocationCoordinates,
22
+ DisplayName: string;
23
+ EntityType?: IMeetingLocationEntityType;
24
+ IsPreviouslyUsed?: boolean;
25
+ LocationSource?: string;
26
+ LocationUri?: string;
27
+ UniqueId?: string;
28
28
  }
@@ -1,12 +1,12 @@
1
- interface IMomentJSObj {
2
- toDate: () => Date;
3
- isValid: () => boolean;
4
- }
5
-
6
-
7
- export type typeMomentJS = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
8
- export type typeMonentJSTimeZone = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
9
- declare global {
10
- var momentJS: typeMomentJS;
11
- var monentJSTimeZone: typeMonentJSTimeZone;
1
+ interface IMomentJSObj {
2
+ toDate: () => Date;
3
+ isValid: () => boolean;
4
+ }
5
+
6
+
7
+ export type typeMomentJS = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
8
+ export type typeMonentJSTimeZone = (inp?: string, format?: string, strict?: boolean) => IMomentJSObj;
9
+ declare global {
10
+ var momentJS: typeMomentJS;
11
+ var monentJSTimeZone: typeMonentJSTimeZone;
12
12
  }
@@ -1,17 +1,17 @@
1
- import { IDictionary } from "./common.types";
2
-
3
- export interface IRegexExpression {
4
- pattern: string;
5
- example: string;
6
- options: string[];
7
- isDefault: boolean;
8
- }
9
-
10
- export interface IRegexList extends IDictionary<IRegexExpression> {
11
- }
12
-
13
- declare global {
14
- interface IModernListSettings {
15
- RegexList?: IRegexList;
16
- }
1
+ import { IDictionary } from "./common.types";
2
+
3
+ export interface IRegexExpression {
4
+ pattern: string;
5
+ example: string;
6
+ options: string[];
7
+ isDefault: boolean;
8
+ }
9
+
10
+ export interface IRegexList extends IDictionary<IRegexExpression> {
11
+ }
12
+
13
+ declare global {
14
+ interface IModernListSettings {
15
+ RegexList?: IRegexList;
16
+ }
17
17
  }
@@ -1,96 +1,96 @@
1
- import { ILocalStorageCacheLifetime } from "./localstoragecache.types";
2
-
3
- export type IRestResponseType = "" | "blob" | "arraybuffer" | "text" | "json" | "document";
4
- // eslint-disable-next-line no-shadow
5
- export enum jsonTypes {
6
- verbose = "application/json; odata=verbose",
7
- minimal = "application/json; odata=minimal",
8
- nometadata = "application/json; odata=nometadata",
9
- standard = "application/json"
10
- }
11
-
12
- // eslint-disable-next-line no-shadow
13
- export enum contentTypes {
14
- xml = "application/xml",
15
- json = "application/json"
16
- }
17
-
18
- export const AllRestCacheOptionsKeys: Required<IRestCacheOptions> = {
19
- allowCache: true,
20
- forceCacheUpdate: true,
21
- localStorageExpiration: 1,
22
- maxAge: 1
23
- };
24
- export interface IRestCacheOptions {
25
- allowCache?: boolean;
26
- /** if allowCache=true and local storage is supported, this will keep the results in local storage for a while */
27
- localStorageExpiration?: number | ILocalStorageCacheLifetime | Date;
28
- /** max age the runtime memeroy cache result is valid for in seconds */
29
- maxAge?: number;
30
- /** when a request allows to be stored in cache (persistent/memory) - signals that we want to update the cached value */
31
- forceCacheUpdate?: boolean;
32
- }
33
-
34
- export interface IRestRequestOptions {
35
- /** default: get if no body sent, otherwise post */
36
- method?: "GET" | "POST";
37
- xHttpMethod?: "MERGE" | "DELETE" | "PUT";
38
- /**default true */
39
- includeDigestInPost?: boolean;
40
- /**default false */
41
- includeDigestInGet?: boolean;
42
- /**default: Accept: jsonTypes.verbose, and (in post only) content-type: jsonTypes.verbose */
43
- headers?: {
44
- [key: string]: string;
45
- Accept?: string;
46
- "content-type"?: string;
47
- /** `Bearer ${token}` */
48
- Authorization?: string;
49
- };
50
- /** allow cache on post requests if you provide a unique key to identify and match */
51
- postCacheKey?: string;
52
- cors?: boolean;
53
- responseType?: IRestResponseType;
54
- /**If set to true, will return the xhr object itself (XMLHttpRequest) (does not support allowCache!) */
55
- returnXhrObject?: boolean;
56
- /** provide a SharePoint web URL, if running a SharePoint request. Will be used to get the right form digest if/when needed. */
57
- spWebUrl?: string;
58
- jsonMetadata?: jsonTypes;
59
- }
60
- export interface IRestOptions extends IRestRequestOptions, IRestCacheOptions {
61
- }
62
-
63
- export interface IRequestObjects {
64
- xhr: XMLHttpRequest;
65
- options: IRestRequestOptions;
66
- cacheOptions: IRestCacheOptions & { cacheKey?: string; };
67
- }
68
-
69
- export type IRequestBody = Document | Blob | BufferSource | FormData | URLSearchParams | string | null;//should be type XMLHttpRequestBodyInit, but some projects don't recognize it for some reason
70
-
71
- export interface IJsonSyncResultBase<T> {
72
- status: number;
73
- errorData?: any;
74
- /** preserve original error message from failed cached result */
75
- errorMessage?: string;
76
- result?: T;
77
- success: boolean;
78
- cachedTime?: number;
79
- }
80
- export interface IJsonSyncResultSuccess<T> extends IJsonSyncResultBase<T> {
81
- result: T;
82
- success: true;
83
- }
84
- export interface IJsonSyncResultError<T> extends IJsonSyncResultBase<T> {
85
- errorData: any;
86
- /** preserve original error message from failed cached result */
87
- errorMessage: string;
88
- success: false;
89
- }
90
- export type IJsonSyncResult<T> = IJsonSyncResultSuccess<T> | IJsonSyncResultError<T>;
91
-
92
- export interface IRestError {
93
- message: string;
94
- errorData?: any;
95
- xhr?: XMLHttpRequest;
1
+ import { ILocalStorageCacheLifetime } from "./localstoragecache.types";
2
+
3
+ export type IRestResponseType = "" | "blob" | "arraybuffer" | "text" | "json" | "document";
4
+ // eslint-disable-next-line no-shadow
5
+ export enum jsonTypes {
6
+ verbose = "application/json; odata=verbose",
7
+ minimal = "application/json; odata=minimal",
8
+ nometadata = "application/json; odata=nometadata",
9
+ standard = "application/json"
10
+ }
11
+
12
+ // eslint-disable-next-line no-shadow
13
+ export enum contentTypes {
14
+ xml = "application/xml",
15
+ json = "application/json"
16
+ }
17
+
18
+ export const AllRestCacheOptionsKeys: Required<IRestCacheOptions> = {
19
+ allowCache: true,
20
+ forceCacheUpdate: true,
21
+ localStorageExpiration: 1,
22
+ maxAge: 1
23
+ };
24
+ export interface IRestCacheOptions {
25
+ allowCache?: boolean;
26
+ /** if allowCache=true and local storage is supported, this will keep the results in local storage for a while */
27
+ localStorageExpiration?: number | ILocalStorageCacheLifetime | Date;
28
+ /** max age the runtime memeroy cache result is valid for in seconds */
29
+ maxAge?: number;
30
+ /** when a request allows to be stored in cache (persistent/memory) - signals that we want to update the cached value */
31
+ forceCacheUpdate?: boolean;
32
+ }
33
+
34
+ export interface IRestRequestOptions {
35
+ /** default: get if no body sent, otherwise post */
36
+ method?: "GET" | "POST";
37
+ xHttpMethod?: "MERGE" | "DELETE" | "PUT";
38
+ /**default true */
39
+ includeDigestInPost?: boolean;
40
+ /**default false */
41
+ includeDigestInGet?: boolean;
42
+ /**default: Accept: jsonTypes.verbose, and (in post only) content-type: jsonTypes.verbose */
43
+ headers?: {
44
+ [key: string]: string;
45
+ Accept?: string;
46
+ "content-type"?: string;
47
+ /** `Bearer ${token}` */
48
+ Authorization?: string;
49
+ };
50
+ /** allow cache on post requests if you provide a unique key to identify and match */
51
+ postCacheKey?: string;
52
+ cors?: boolean;
53
+ responseType?: IRestResponseType;
54
+ /**If set to true, will return the xhr object itself (XMLHttpRequest) (does not support allowCache!) */
55
+ returnXhrObject?: boolean;
56
+ /** provide a SharePoint web URL, if running a SharePoint request. Will be used to get the right form digest if/when needed. */
57
+ spWebUrl?: string;
58
+ jsonMetadata?: jsonTypes;
59
+ }
60
+ export interface IRestOptions extends IRestRequestOptions, IRestCacheOptions {
61
+ }
62
+
63
+ export interface IRequestObjects {
64
+ xhr: XMLHttpRequest;
65
+ options: IRestRequestOptions;
66
+ cacheOptions: IRestCacheOptions & { cacheKey?: string; };
67
+ }
68
+
69
+ export type IRequestBody = Document | Blob | BufferSource | FormData | URLSearchParams | string | null;//should be type XMLHttpRequestBodyInit, but some projects don't recognize it for some reason
70
+
71
+ export interface IJsonSyncResultBase<T> {
72
+ status: number;
73
+ errorData?: any;
74
+ /** preserve original error message from failed cached result */
75
+ errorMessage?: string;
76
+ result?: T;
77
+ success: boolean;
78
+ cachedTime?: number;
79
+ }
80
+ export interface IJsonSyncResultSuccess<T> extends IJsonSyncResultBase<T> {
81
+ result: T;
82
+ success: true;
83
+ }
84
+ export interface IJsonSyncResultError<T> extends IJsonSyncResultBase<T> {
85
+ errorData: any;
86
+ /** preserve original error message from failed cached result */
87
+ errorMessage: string;
88
+ success: false;
89
+ }
90
+ export type IJsonSyncResult<T> = IJsonSyncResultSuccess<T> | IJsonSyncResultError<T>;
91
+
92
+ export interface IRestError {
93
+ message: string;
94
+ errorData?: any;
95
+ xhr?: XMLHttpRequest;
96
96
  }